Skip to content

Commit

Permalink
Making adjustments per recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
appatalks committed Jan 2, 2025
1 parent 13f6f4f commit f493a62
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="dev.chungjungsoo.gptmobile"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,19 @@ fun ChatScreen(
val question by chatViewModel.question.collectAsStateWithLifecycle()
val appEnabledPlatforms by chatViewModel.enabledPlatformsInApp.collectAsStateWithLifecycle()
val editedQuestion by chatViewModel.editedQuestion.collectAsStateWithLifecycle()

val openaiLoadingState by chatViewModel.openaiLoadingState.collectAsStateWithLifecycle()
val anthropicLoadingState by chatViewModel.anthropicLoadingState.collectAsStateWithLifecycle()
val googleLoadingState by chatViewModel.googleLoadingState.collectAsStateWithLifecycle()
val groqLoadingState by chatViewModel.groqLoadingState.collectAsStateWithLifecycle()
val ollamaLoadingState by chatViewModel.ollamaLoadingState.collectAsStateWithLifecycle()
val geminiNanoLoadingState by chatViewModel.geminiNanoLoadingState.collectAsStateWithLifecycle()

val userMessage by chatViewModel.userMessage.collectAsStateWithLifecycle()

val openAIMessage by chatViewModel.openAIMessage.collectAsStateWithLifecycle()
val anthropicMessage by chatViewModel.anthropicMessage.collectAsStateWithLifecycle()
val googleMessage by chatViewModel.googleMessage.collectAsStateWithLifecycle()
val groqMessage by chatViewModel.groqMessage.collectAsStateWithLifecycle()
val ollamaMessage by chatViewModel.ollamaMessage.collectAsStateWithLifecycle()

val geminiNano by chatViewModel.geminiNanoMessage.collectAsStateWithLifecycle()

val canUseChat = (chatViewModel.enabledPlatformsInChat.toSet() - appEnabledPlatforms.toSet()).isEmpty()
val groupedMessages = remember(messages) { groupMessages(messages) }
val latestMessageIndex = groupedMessages.keys.maxOrNull() ?: 0
Expand Down Expand Up @@ -366,7 +361,7 @@ private fun groupMessages(messages: List<Message>): HashMap<Int, MutableList<Mes
@OptIn(ExperimentalMaterial3Api::class)
private fun ChatTopBar(
title: String,
isChatTitleUpdateEnabled: Boolean,
isMenuItemEnabled: Boolean,
onBackAction: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
onChatTitleItemClick: () -> Unit,
Expand All @@ -392,7 +387,7 @@ private fun ChatTopBar(

ChatDropdownMenu(
isDropDownMenuExpanded = isDropDownMenuExpanded,
isChatTitleUpdateEnabled = isChatTitleUpdateEnabled,
isMenuItemEnabled = isMenuItemEnabled,
onDismissRequest = { isDropDownMenuExpanded = false },
onChatTitleItemClick = {
onChatTitleItemClick.invoke()
Expand All @@ -408,7 +403,7 @@ private fun ChatTopBar(
@Composable
fun ChatDropdownMenu(
isDropDownMenuExpanded: Boolean,
isChatTitleUpdateEnabled: Boolean,
isMenuItemEnabled: Boolean,
onDismissRequest: () -> Unit,
onChatTitleItemClick: () -> Unit,
onExportChatItemClick: () -> Unit
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -236,8 +233,7 @@ class ChatViewModel @Inject constructor(
}

fun exportChat() {
val context = getApplication<Application>().applicationContext

val context = application.applicationContext
// Build the chat history in Markdown format
val chatHistoryMarkdown = buildString {
appendLine("# Chat Export: \"${chatRoom.value.title}\"")
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="external_files" path="." />
</paths>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path
name="external_files"
path="." />
</paths>

0 comments on commit f493a62

Please sign in to comment.