-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff with branch that was trying to move the sessionviewmodel away from the main screen.txt
565 lines (534 loc) · 60.8 KB
/
diff with branch that was trying to move the sessionviewmodel away from the main screen.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e3b896a..d58363b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
+<!-- This manifest declares the backup rules for this app. It uses the
+ backup_rules.xml file to define what data the app will back up. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hello_world"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECORD_AUDIO" />
@@ -24,17 +26,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
-
- <!-- Add the FileProvider here -->
- <provider
- android:name="androidx.core.content.FileProvider"
- android:authorities="com.example.hello_world.provider"
- android:exported="false"
- android:grantUriPermissions="true">
- <meta-data
- android:name="android.support.FILE_PROVIDER_PATHS"
- android:resource="@xml/provider_paths" />
- </provider>
-
</application>
+
</manifest>
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hello_world/MainActivity.kt b/app/src/main/java/com/example/hello_world/MainActivity.kt
index ca2ab67..cf4a4d5 100644
--- a/app/src/main/java/com/example/hello_world/MainActivity.kt
+++ b/app/src/main/java/com/example/hello_world/MainActivity.kt
@@ -51,17 +51,17 @@ class MainActivity : AppCompatActivity() {
private lateinit var textToSpeechServiceState: MutableState<TextToSpeechService>
private lateinit var snackbarHostState: SnackbarHostState
- val sessionViewModel: SessionViewModel by viewModels {
- SessionViewModelFactory(
- conversationId = null,
- context = this@MainActivity,
- configPacksViewModel = configPacksViewModel,
- openAiApiService = openAiApiService,
- conversationRepository = conversationRepository,
- textToSpeechServiceState = textToSpeechServiceState,
- snackbarHostState = snackbarHostState
- )
- }
+// val sessionViewModel: SessionViewModel by viewModels {
+// SessionViewModelFactory(
+// conversationId = null,
+// context = this@MainActivity,
+// configPacksViewModel = configPacksViewModel,
+// openAiApiService = openAiApiService,
+// conversationRepository = conversationRepository,
+// textToSpeechServiceState = textToSpeechServiceState,
+// snackbarHostState = snackbarHostState
+// )
+// }
@@ -101,6 +101,17 @@ class MainActivity : AppCompatActivity() {
}
composable("session/{conversationId}") { backStackEntry ->
val conversationId = backStackEntry.arguments?.getString("conversationId")?.let { UUID.fromString(it) }
+ val sessionViewModel = remember {
+ SessionViewModel(
+ conversationId = conversationId!!,
+ context = this@MainActivity,
+ configPacksViewModel = configPacksViewModel,
+ openAiApiService = openAiApiService,
+ conversationRepository = conversationRepository,
+ textToSpeechServiceState = textToSpeechServiceState,
+ snackbarHostState = snackbarHostState
+ )
+ }
SessionScreen(
sessionViewModel,
configPacksViewModel,
@@ -115,7 +126,7 @@ class MainActivity : AppCompatActivity() {
val savedConversationsViewModel = remember { SavedConversationsViewModel(conversationRepository,this@MainActivity) }
SavedConversationsScreen(
viewModel = savedConversationsViewModel,
- onConversationSelected = { conversationId ->
+ onConversationSelected = { conversationId, sessionViewModel ->
Log.d("SessionScreen", "Selected conversation ID: ${conversationId}")
navController.navigate("session/${conversationId.toString()}")
sessionViewModel.loadConversationWithId(conversationId)
@@ -123,7 +134,7 @@ class MainActivity : AppCompatActivity() {
},
onBack = { navController.popBackStack() },
- onNewConversationClicked = {
+ onNewConversationClicked = { sessionViewModel ->
savedConversationsViewModel.viewModelScope.launch {
val newConversationId = savedConversationsViewModel.createNewConversation()
navController.navigate("session/${newConversationId.toString()}")
diff --git a/app/src/main/java/com/example/hello_world/data/repository/LocalRoomConversationRepository.kt b/app/src/main/java/com/example/hello_world/data/repository/LocalRoomConversationRepository.kt
index 33f103b..d811b9f 100644
--- a/app/src/main/java/com/example/hello_world/data/repository/LocalRoomConversationRepository.kt
+++ b/app/src/main/java/com/example/hello_world/data/repository/LocalRoomConversationRepository.kt
@@ -37,7 +37,7 @@ class LocalRoomConversationRepository(private val context: Context) : IConversat
.add(KotlinJsonAdapterFactory())
.build()
override suspend fun saveConversation(conversation: Conversation) {
- Log.d("LocalRoomRepo", "Saving conversation with ID: ${conversation.id}")
+ Log.d("LocalRoomRepo", "Saving conversation with ID: ${conversation.id} from the first line of fun saveConversation()")
val configPackJson = moshi.adapter(ConfigPack::class.java).toJson(conversation.configPack)
withContext(Dispatchers.IO) {
val conversationEntity = LocalConversationEntity(
@@ -57,41 +57,38 @@ class LocalRoomConversationRepository(private val context: Context) : IConversat
audioFilePath = message.audioFilePath.value
)
}
+ Log.d("LocalRoomRepo", "Saving conversation to conversationDao with ID: ${conversation.id} from right before the saveConversation() invocation in fun saveConversation()")
conversationDao.saveConversation(conversationEntity, messageEntities)
}
}
- override suspend fun loadConversation(conversationId: UUID): Conversation? {
+ override suspend fun loadConversation(conversationId: UUID): Conversation {
Log.d("LocalRoomRepo", "Loading conversation with ID: $conversationId")
return withContext(Dispatchers.IO) {
- val conversationEntity = conversationDao.getConversation(conversationId.toString())
+ val conversationEntity = conversationDao.getConversation(conversationId.toString())!!
val messageEntities = conversationDao.getMessages(conversationId.toString())
- val configPack = moshi.adapter(ConfigPack::class.java).fromJson(conversationEntity?.profileJson)
- if (conversationEntity != null && configPack != null) {
- val configPack = moshi.adapter(ConfigPack::class.java).fromJson(conversationEntity.profileJson)
- configPack?.let {
- val messages = messageEntities.map { entity ->
- ConversationMessage(
- sender = entity.sender,
- message = entity.message,
- audioFilePath = mutableStateOf(entity.audioFilePath)
- )
- }.toMutableList()
+ val configPack = moshi.adapter(ConfigPack::class.java).fromJson(conversationEntity.profileJson)
- Conversation(
- id = UUID.fromString(conversationEntity.id),
- messages = messages,
- configPack = it,
- createdAt = conversationEntity.createdAt,
- title = conversationEntity.title.orEmpty(),
- dateStarted = conversationEntity.dateStarted,
- dateLastSaved = conversationEntity.dateLastSaved,
- messageCount = conversationEntity.messageCount
- )
- }
- } else {
- null
- }
+ val messages = messageEntities.map { entity ->
+ ConversationMessage(
+ sender = entity.sender,
+ message = entity.message,
+ audioFilePath = mutableStateOf(entity.audioFilePath)
+ )
+ }.toMutableList()
+
+ configPack?.let {
+ Conversation(
+ id = UUID.fromString(conversationEntity.id),
+ messages = messages,
+ configPack = it,
+ createdAt = conversationEntity.createdAt,
+ title = conversationEntity.title.orEmpty(),
+ dateStarted = conversationEntity.dateStarted,
+ dateLastSaved = conversationEntity.dateLastSaved,
+ messageCount = conversationEntity.messageCount
+ )
+ } ?: throw IllegalStateException("ConfigPack cannot be null")
}
}
@@ -111,7 +108,7 @@ class LocalRoomConversationRepository(private val context: Context) : IConversat
configPack?.let {
Conversation(
id = UUID.fromString(entity.id),
- messages = mutableListOf(), // We don't need messages for the saved conversations list
+ messages = mutableListOf(),
configPack = it,
createdAt = entity.createdAt,
title = entity.title.orEmpty(),
@@ -183,7 +180,7 @@ class LocalRoomConversationRepository(private val context: Context) : IConversat
}
}
}
-
+ Log.d("LocalRoomRepo", "Starting to copy audio files to external storage")
// Copy audio files to external storage
val audioFolderPath = copyAudioFilesToExternal(conversations, context)
@@ -198,6 +195,9 @@ class LocalRoomConversationRepository(private val context: Context) : IConversat
)
}
+// Copy audio files to external storage
+// val audioFolderPath = copyAudioFilesToExternal(conversations, context)
+
// Create ExportData object with updated conversations
val exportData = ExportData(conversations = updatedConversations)
@@ -252,26 +252,72 @@ class LocalRoomConversationRepository(private val context: Context) : IConversat
}
suspend fun copyAudioFilesToExternal(conversations: List<Conversation>, context: Context): String {
- val externalFolderPath = context.getExternalFilesDir(Environment.DIRECTORY_MUSIC)?.absolutePath
- val audioFolder = File(externalFolderPath, "ConversationAudio")
- if (!audioFolder.exists()) {
- audioFolder.mkdirs()
+ Log.d("LocalRoomRepo", "Entered copyAudioFilesToExternal function")
+ val contentValues = ContentValues().apply {
+ put(MediaStore.MediaColumns.MIME_TYPE, "audio/*")
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS + "/ConversationAudio")
+ put(MediaStore.MediaColumns.IS_PENDING, 1)
+ }
}
+ val contentResolver = context.contentResolver
+
conversations.forEach { conversation ->
conversation.messages.forEach { message ->
val audioFilePath = message.audioFilePath.value
if (audioFilePath.isNotEmpty()) {
val sourceFile = File(audioFilePath)
- val destinationFile = File(audioFolder, sourceFile.name)
- withContext(Dispatchers.IO) {
- sourceFile.copyTo(destinationFile, overwrite = true)
+ Log.d("LocalRoomRepo", "About to check if source audio file exists")
+ if (sourceFile.exists() && sourceFile.length() > 0) {
+ Log.d("LocalRoomRepo", "Source audio file path: $audioFilePath")
+ Log.d("LocalRoomRepo", "Source audio file exists: ${sourceFile.exists()}")
+ val destinationFileName = sourceFile.name
+
+ contentValues.apply {
+ put(MediaStore.MediaColumns.DATA, "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)}/ConversationAudio/$destinationFileName")
+ put(MediaStore.MediaColumns.DISPLAY_NAME, destinationFileName)
+ Log.d("LocalRoomRepo", "Destination audio file path: ${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)}/ConversationAudio/$destinationFileName")
}
- }
+
+ val uri = contentResolver.insert(MediaStore.Files.getContentUri("external"), contentValues)
+
+ if (uri != null) {
+ withContext(Dispatchers.IO) {
+ if (uri != null && sourceFile.isFile) {
+ withContext(Dispatchers.IO) {
+ try {
+ contentResolver.openInputStream(Uri.fromFile(sourceFile))?.use { inputStream ->
+ contentResolver.openOutputStream(uri)?.use { outputStream ->
+ inputStream.copyTo(outputStream)
+ }
+ }
+ Log.d("LocalRoomRepo", "Successfully copied audio file: ${sourceFile.name}")
+ } catch (e: Exception) {
+ Log.e("LocalRoomRepo", "Error copying audio file: ${sourceFile.name}", e)
+ }
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ contentValues.clear()
+ contentValues.put(MediaStore.MediaColumns.IS_PENDING, 0)
+ contentResolver.update(uri, contentValues, null, null)
+ }
+ }
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ contentValues.clear()
+ contentValues.put(MediaStore.MediaColumns.IS_PENDING, 0)
+ contentResolver.update(uri, contentValues, null, null)
+ }
+ }
+ }}
}
}
-
- return audioFolder.absolutePath
+ Log.d("LocalRoomRepo", "About to return the filepath")
+ return "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)}/ConversationAudio"
+ Log.d("LocalRoomRepo", "just returned the filepath")
}
diff --git a/app/src/main/java/com/example/hello_world/diff_output.txt b/app/src/main/java/com/example/hello_world/diff_output.txt
index ed46604..a8a8a11 100644
Binary files a/app/src/main/java/com/example/hello_world/diff_output.txt and b/app/src/main/java/com/example/hello_world/diff_output.txt differ
diff --git a/app/src/main/java/com/example/hello_world/services/media_playback/AndroidMediaPlaybackManager.kt b/app/src/main/java/com/example/hello_world/services/media_playback/AndroidMediaPlaybackManager.kt
index 026cb42..5b4840e 100644
--- a/app/src/main/java/com/example/hello_world/services/media_playback/AndroidMediaPlaybackManager.kt
+++ b/app/src/main/java/com/example/hello_world/services/media_playback/AndroidMediaPlaybackManager.kt
@@ -53,7 +53,7 @@ class AndroidMediaPlaybackManager : MediaPlaybackManager {
try {
mediaPlayer = MediaPlayer().apply {
Log.d("AndroidMediaPlaybackManager", "Playing audio from file: $filePath")
- setDataSource(filePath)
+ setDataSource(filePath) // this is where the problem is, it's line 54
setOnCompletionListener {
resetPlaybackPosition()
onFinish?.invoke()
@@ -61,13 +61,13 @@ class AndroidMediaPlaybackManager : MediaPlaybackManager {
}
prepare()
start()
+
}
currentFilePath = filePath // Update the currentFilePath here
} catch (e: IOException) {
Toast.makeText(context, "Audio file not found or corrupted", Toast.LENGTH_SHORT).show()
Log.e("AndroidMediaPlaybackManager", "Error setting data source for media player", e)
}
- currentFilePath = filePath // Update the currentFilePath here
}
mediaController?.hide()
mediaController = MediaController(context)
diff --git a/app/src/main/java/com/example/hello_world/ui/saved_conversations/view/SavedConversationsScreen.kt b/app/src/main/java/com/example/hello_world/ui/saved_conversations/view/SavedConversationsScreen.kt
index fe048c8..d92c397 100644
--- a/app/src/main/java/com/example/hello_world/ui/saved_conversations/view/SavedConversationsScreen.kt
+++ b/app/src/main/java/com/example/hello_world/ui/saved_conversations/view/SavedConversationsScreen.kt
@@ -56,6 +56,7 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.viewModelScope
import com.example.hello_world.ui.saved_conversations.viewmodel.SavedConversationsViewModel
+import com.example.hello_world.ui.session.viewmodel.SessionViewModel
import kotlinx.coroutines.launch
@Composable
@@ -63,9 +64,9 @@ import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterialApi::class)
fun SavedConversationsScreen(
viewModel: SavedConversationsViewModel,
- onConversationSelected: (UUID) -> Unit,
+ onConversationSelected: (UUID, SessionViewModel) -> Unit,
onBack: () -> Unit,
- onNewConversationClicked: () -> Unit
+ onNewConversationClicked: (SessionViewModel) -> Unit
) {
val permissionLauncher = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
if (isGranted) {
@@ -148,7 +149,18 @@ fun SavedConversationsScreen(
conversation = conversation,
onClick = {
Log.d("SavedConversationsScreen", "Selected conversation ID: ${conversation.id}")
- onConversationSelected(conversation.id)
+ val sessionViewModel = remember {
+ SessionViewModel(
+ conversationId = conversation.id,
+ context = LocalContext.current,
+ configPacksViewModel = configPacksViewModel,
+ openAiApiService = openAiApiService,
+ conversationRepository = conversationRepository,
+ textToSpeechServiceState = textToSpeechServiceState,
+ snackbarHostState = snackbarHostState
+ )
+ }
+ onConversationSelected(conversation.id, sessionViewModel)
},
onDeleteClicked = { viewModel.deleteConversation(conversation.id) }
)
diff --git a/app/src/main/java/com/example/hello_world/ui/session/view/SessionScreen.kt b/app/src/main/java/com/example/hello_world/ui/session/view/SessionScreen.kt
index d23d342..4737a9a 100644
--- a/app/src/main/java/com/example/hello_world/ui/session/view/SessionScreen.kt
+++ b/app/src/main/java/com/example/hello_world/ui/session/view/SessionScreen.kt
@@ -80,16 +80,16 @@ fun SessionScreen(
) {
val coroutineScope = rememberCoroutineScope()
val focusRequester = remember { FocusRequester() }
- DisposableEffect(Unit) {
-
- Log.d("SessionScreen", "sessionViewModel.conversationId: ${sessionViewModel.conversationId}")
- sessionViewModel.conversationId?.let {
- Log.d("SessionScreen", "Before `sessionViewModel.loadConversation(it)` within the sessionViewModel.conversationId?.let {/.../} block ")
- sessionViewModel.loadConversation(it)
- Log.d("SessionScreen", "After `sessionViewModel.loadConversation(it)` within the sessionViewModel.conversationId?.let {/.../} block ")
- }
- onDispose { }
- }
+// DisposableEffect(Unit) {
+//
+// Log.d("SessionScreen", "sessionViewModel.conversationId: ${sessionViewModel.conversationId}")
+// sessionViewModel.conversationId?.let {
+// Log.d("SessionScreen", "Before `sessionViewModel.loadConversation(it)` within the sessionViewModel.conversationId?.let {/.../} block ")
+//// sessionViewModel.loadConversation(it)
+// Log.d("SessionScreen", "After `sessionViewModel.loadConversation(it)` within the sessionViewModel.conversationId?.let {/.../} block ")
+// }
+// onDispose { }
+// }
val shareTextLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult()) { result ->
// You can handle the result of the sharing action here if needed
@@ -112,6 +112,7 @@ fun SessionScreen(
val messages = sessionViewModel.conversationMessages
Log.d("SessionScreen", "Number of messages in session screen: ${messages.size}")
sessionViewModel.autosaveConversation()
+ Log.d("SessionScreen", "sessionViewModel.autosaveConversation() called")
LaunchedEffect(Unit) {
if (scrollToBottomClicked.value) {
val targetIndex = messages.size - 1
@@ -134,6 +135,7 @@ fun SessionScreen(
val updatedConversation = sessionViewModel.conversationManager.conversation.copy(title = newTitle)
sessionViewModel.conversationManager.conversation = updatedConversation
sessionViewModel.conversationRepository.saveConversation(updatedConversation)
+ Log.d("SessionScreen", "Updated conversation: $updatedConversation in fun onTitleEditClicked(newTitle: String)")
}
editedTitle.value = TextFieldValue(newTitle, TextRange(newTitle.length))
}
diff --git a/app/src/main/java/com/example/hello_world/ui/session/viewmodel/SessionViewModel.kt b/app/src/main/java/com/example/hello_world/ui/session/viewmodel/SessionViewModel.kt
index 86424f0..390d3f9 100644
--- a/app/src/main/java/com/example/hello_world/ui/session/viewmodel/SessionViewModel.kt
+++ b/app/src/main/java/com/example/hello_world/ui/session/viewmodel/SessionViewModel.kt
@@ -28,7 +28,7 @@ import com.example.hello_world.withExponentialBackoff
class SessionViewModel(
- var conversationId: UUID?,
+ var conversationId: UUID,
val context: Context,
val configPacksViewModel: ConfigPacksViewModel,
val openAiApiService: OpenAiApiService,
@@ -57,27 +57,16 @@ class SessionViewModel(
val isListening: Boolean get() = _isListening.value
- fun loadInitialConversation(conversationId: UUID? = null) {
+ fun loadInitialConversation(conversationId: UUID) {
Log.d("SessionViewModel", "fun loadInitialConversation from before the `viewModelScope.launch` block, loadInitialConversation called with conversationId: $conversationId")
viewModelScope.launch {
Log.d("SessionViewModel", "fun loadInitialConversation from within the `viewModelScope.launch` block, loadInitialConversation called with conversationId: $conversationId")
- val loadedConversation = if (conversationId != null) {
- conversationsManager.loadConversation(conversationId)
- } else {
- null
- }
- if (loadedConversation != null) {
- Log.d("SessionViewModel", "fun loadInitialConversation Loaded conversation: $loadedConversation")
- conversationManager.conversation = loadedConversation
- conversationMessages.clear()
- conversationMessages.addAll(conversationManager.conversation.messages)
- } else {
- // Use the default profile for the initial conversation
- val initialConversation = Conversation(configPack = ConfigPack.defaultConfigPack)
- conversationManager.conversation = initialConversation
- conversationMessages.clear()
- conversationMessages.addAll(conversationManager.conversation.messages)
- }
+ val loadedConversation = conversationsManager.loadConversation(conversationId)
+
+ Log.d("SessionViewModel", "fun loadInitialConversation Loaded conversation: $loadedConversation")
+ conversationManager.conversation = loadedConversation!!
+ conversationMessages.clear()
+ conversationMessages.addAll(conversationManager.conversation.messages)
Log.d("SessionViewModel", "fun loadInitialConversation conversationMessages after loadInitialConversation: $conversationMessages")
}
}
@@ -86,6 +75,7 @@ class SessionViewModel(
fun saveCurrentConversation() {
viewModelScope.launch {
conversationsManager.saveConversation(conversationManager.conversation)
+ Log.d("SessionViewModel", "fun saveCurrentConversation conversationMessages after saveCurrentConversation: $conversationMessages")
}
}
@@ -122,6 +112,7 @@ class SessionViewModel(
conversationManager.addMessage(assistantMessageObj)
conversationMessages.add(assistantMessageObj)
autosaveConversation()
+ Log.d("SessionViewModel", "fun sendUserMessageToOpenAi autosaveConversation called")
textToSpeechServiceState?.value?.renderSpeech(responseText.replace("\n", " "), onFinish = {
if (conversationManager.conversation.messages.isNotEmpty()) {
@@ -137,7 +128,8 @@ class SessionViewModel(
}
}, audioFilePathState = assistantMessageObj.audioFilePath)
_isAppSpeaking.value = true
- autosaveConversation()
+// autosaveConversation()
+// Log.d("SessionViewModel", "fun sendUserMessageToOpenAi autosaveConversation called")
}
fun updateMessage(index: Int, updatedMessage: ConversationMessage) {
@@ -190,6 +182,7 @@ class SessionViewModel(
sendUserMessageToOpenAi(userMessage) // Pass the userMessage parameter here
}
autosaveConversation()
+ Log.d("SessionViewModel", "log: from within the OnTriggerWordDetected function, autosaveConversation() was just called, isListening: $isListening, instance: $this, memory location: ${System.identityHashCode(this)}")
}
fun loadConversation(conversationId: UUID) {
@@ -200,14 +193,12 @@ class SessionViewModel(
}
init {
- Log.d("SessionViewModel", "init about to run `loadInitialConversation(conversationId)`")
- loadInitialConversation(conversationId)
startPeriodicListeningCheck()
}
fun loadConversationWithId(conversationId: UUID) {
this.conversationId = conversationId
- loadInitialConversation()
+ loadInitialConversation(conversationId)
}
@@ -220,6 +211,7 @@ class SessionViewModel(
viewModelScope.launch {
val updatedConversation = conversationManager.conversation.copy(title = saveDialogTitle.value)
conversationsManager.saveConversation(conversationManager.conversation)
+ Log.d("SessionViewModel", "log: onSaveDialogConfirmed called, instance: $this, memory location: ${System.identityHashCode(this)}")
conversationManager.conversation = updatedConversation
}
showSaveDialog.value = false
@@ -234,7 +226,7 @@ class SessionViewModel(
}
class SessionViewModelFactory(
- private val conversationId: UUID?,
+ private val conversationId: UUID,
private val context: Context,
private val configPacksViewModel: ConfigPacksViewModel,
private val openAiApiService: OpenAiApiService,
diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml
deleted file mode 100644
index 7e6caaf..0000000
--- a/app/src/main/res/xml/file_paths.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<paths xmlns:android="http://schemas.android.com/apk/res/android">
- <external-path
- name="my_audio_files"
- path="Android/data/com.example.hello_world/files/" />
-</paths>
\ No newline at end of file
diff --git a/app/src/main/res/xml/provider_paths.xml b/app/src/main/res/xml/provider_paths.xml
deleted file mode 100644
index 219879e..0000000
--- a/app/src/main/res/xml/provider_paths.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<paths xmlns:android="http://schemas.android.com/apk/res/android">
- <external-path name="external_files" path="." />
- <external-cache-path name="external_cache" path="." />
- <cache-path name="cache" path="." />
- <files-path name="files" path="." />
-</paths>
\ No newline at end of file
-
-PlantUML version 1.2022.7(Mon Aug 22 13:01:30 EDT 2022)
-(GPL source distribution)
-Java Runtime: Java(TM) SE Runtime Environment
-JVM: Java HotSpot(TM) 64-Bit Server VM
-Default Encoding: Cp1252
-Language: en
-Country: US
---></g></svg>
\ No newline at end of file