From f493a62da5299eb682bd15059e2e32a98396c8a8 Mon Sep 17 00:00:00 2001 From: appatalks Date: Thu, 2 Jan 2025 12:05:52 -0600 Subject: [PATCH] Making adjustments per recommendations https://github.com/Taewan-P/gpt_mobile/pull/150#pullrequestreview-2527036640 --- .idea/vcs.xml | 3 +-- app/src/main/AndroidManifest.xml | 2 +- .../gptmobile/presentation/ui/chat/ChatScreen.kt | 14 +++++--------- .../presentation/ui/chat/ChatViewModel.kt | 13 +++++-------- app/src/main/res/xml/file_paths.xml | 8 +++++--- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 4eb1814..5ace414 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ - - \ No newline at end of file + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4e99f56..e40bc3a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,7 +33,7 @@ ): HashMap Unit, scrollBehavior: TopAppBarScrollBehavior, onChatTitleItemClick: () -> Unit, @@ -392,7 +387,7 @@ private fun ChatTopBar( ChatDropdownMenu( isDropDownMenuExpanded = isDropDownMenuExpanded, - isChatTitleUpdateEnabled = isChatTitleUpdateEnabled, + isMenuItemEnabled = isMenuItemEnabled, onDismissRequest = { isDropDownMenuExpanded = false }, onChatTitleItemClick = { onChatTitleItemClick.invoke() @@ -408,7 +403,7 @@ private fun ChatTopBar( @Composable fun ChatDropdownMenu( isDropDownMenuExpanded: Boolean, - isChatTitleUpdateEnabled: Boolean, + isMenuItemEnabled: Boolean, onDismissRequest: () -> Unit, onChatTitleItemClick: () -> Unit, onExportChatItemClick: () -> Unit @@ -419,12 +414,13 @@ fun ChatDropdownMenu( onDismissRequest = onDismissRequest ) { DropdownMenuItem( - enabled = isChatTitleUpdateEnabled, + enabled = isMenuItemEnabled, text = { Text(text = stringResource(R.string.update_chat_title)) }, onClick = onChatTitleItemClick ) /* Export Chat */ DropdownMenuItem( + enabled = isMenuItemEnabled, text = { Text(text = stringResource(R.string.export_chat)) }, onClick = { onExportChatItemClick() diff --git a/app/src/main/kotlin/dev/chungjungsoo/gptmobile/presentation/ui/chat/ChatViewModel.kt b/app/src/main/kotlin/dev/chungjungsoo/gptmobile/presentation/ui/chat/ChatViewModel.kt index 8a157c7..ebc731f 100644 --- a/app/src/main/kotlin/dev/chungjungsoo/gptmobile/presentation/ui/chat/ChatViewModel.kt +++ b/app/src/main/kotlin/dev/chungjungsoo/gptmobile/presentation/ui/chat/ChatViewModel.kt @@ -3,7 +3,6 @@ package dev.chungjungsoo.gptmobile.presentation.ui.chat import android.content.Intent import android.util.Log import android.app.Application -import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -25,13 +24,11 @@ import kotlinx.coroutines.launch @HiltViewModel class ChatViewModel @Inject constructor( - application: Application, + private val application: Application, savedStateHandle: SavedStateHandle, private val chatRepository: ChatRepository, private val settingRepository: SettingRepository -/* ) : ViewModel() { */ -) : AndroidViewModel(application) { - +) : ViewModel() { sealed class LoadingState { data object Idle : LoadingState() data object Loading : LoadingState() @@ -236,8 +233,7 @@ class ChatViewModel @Inject constructor( } fun exportChat() { - val context = getApplication().applicationContext - + val context = application.applicationContext // Build the chat history in Markdown format val chatHistoryMarkdown = buildString { appendLine("# Chat Export: \"${chatRoom.value.title}\"") @@ -262,7 +258,8 @@ class ChatViewModel @Inject constructor( file.writeText(chatHistoryMarkdown) // Share the file - val uri = androidx.core.content.FileProvider.getUriForFile(context, "dev.chungjungsoo.gptmobile", file) + // https://stackoverflow.com/questions/56598480/couldnt-find-meta-data-for-provider-with-authority + val uri = androidx.core.content.FileProvider.getUriForFile(context, "dev.chungjungsoo.gptmobile" + ".fileprovider", file) val shareIntent = Intent(Intent.ACTION_SEND).apply { type = "text/markdown" putExtra(Intent.EXTRA_STREAM, uri) diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml index 6377fe7..5e91a74 100644 --- a/app/src/main/res/xml/file_paths.xml +++ b/app/src/main/res/xml/file_paths.xml @@ -1,4 +1,6 @@ - - - + + + \ No newline at end of file