8000 UI and UX changes added. by divyesh11 · Pull Request #9 · eka-care/ai-chat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

UI and UX changes added. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/deploymentTargetSelector.xml

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

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(platform(libs.androidx.compose.bom))
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/eka/conversation/ChatInit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import android.content.Context
import android.content.Intent
import com.eka.conversation.common.models.ChatInitConfiguration
import com.eka.conversation.ui.presentation.activities.ConversationActivity
import com.eka.conversation.ui.presentation.viewmodels.ChatViewModel

object ChatInit {
private var configuration : ChatInitConfiguration? = null
private var viewModel: ChatViewModel? = null

fun initialize(
chatInitConfiguration : ChatInitConfiguration,
Expand All @@ -23,6 +25,14 @@ object ChatInit {
return configuration!!
}

fun setChatViewModel(chatViewModel: ChatViewModel) {
viewModel = chatViewModel
}

fun getChatViewModel(): ChatViewModel? {
return viewModel
}

fun changeConfiguration(
chatInitConfiguration: ChatInitConfiguration,
) {
Expand Down
DDB0
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.eka.conversation.common.models

import androidx.annotation.Keep
import androidx.compose.runtime.Composable
import com.eka.conversation.features.audio.AudioProcessor

@Keep
data class AudioFeatureConfiguration(
val isEnabled: Boolean = true,
val audioProcessorType: AudioProcessorType = AudioProcessorType.GOOGLE_SPEECH_RECOGNIZER,
val audioProcessor: AudioProcessor? = null,
val recordingComponent: @Composable ((Long, onStop: () -> Unit) -> Unit)? = null,
val loadingComponent: @Composable (() -> Unit)? = null
)

enum class AudioProcessorType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.eka.conversation.common.models

import androidx.compose.runtime.Composable
import com.eka.conversation.data.local.db.entities.MessageEntity

data class ChatGeneralConfiguration(
val isChatFirstScreen: Boolean = true,
val shouldShowThreadsIconOnChatScreen: Boolean = true,
val chatContext: String,
val chatSubContext: String,
val chatSessionConfig: String,
val onSessionInvokeNetworkConfiguration: (String) -> NetworkConfiguration
val onSessionInvokeNetworkConfiguration: (String) -> NetworkConfiguration,
val isSortEnabled: Boolean = true,
val isSearchEnabled: Boolean = true,
val sortBottomSheetLayout: @Composable (() -> Unit) -> Unit?,
val onSortItemClick: (List<MessageEntity>) -> List<MessageEntity>,
val sessionIdentity: String?,
val shouldUseExistingSession: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.room.Query
import androidx.room.Update
import com.eka.conversation.common.Constants
import com.eka.conversation.data.local.db.entities.MessageEntity
import com.eka.conversation.data.local.db.entities.models.MessageRole
import kotlinx.coroutines.flow.Flow

@Dao
Expand All 2E18 @@ -31,6 +30,9 @@ interface MessageDao {
@Query("SELECT session_id FROM ${Constants.MESSAGES_TABLE_NAME} ORDER BY created_at DESC LIMIT 1")
fun getLastSessionId() : Flow<String>

@Query("SELECT session_id FROM ${Constants.MESSAGES_TABLE_NAME} WHERE session_identity = :sessionIdentity LIMIT 1")
suspend fun getSessionIdBySessionIdentity(sessionIdentity: String): String?

@Query("""
SELECT * FROM ${Constants.MESSAGES_TABLE_NAME} WHERE (msg_id,session_id) IN (
SELECT msg_id,session_id FROM ${Constants.MESSAGES_FTS_TABLE_NAME} WHERE message_text MATCH :query or chat_context MATCH :query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.eka.conversation.data.local.db.entities.MessageFile
MessageFile::class,
MessageFTSEntity::class
],
version = 2,
version = 3,
exportSchema = false
)
@TypeConverters(Converters::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.annotation.Keep
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Fts4
import androidx.room.PrimaryKey
import com.eka.conversation.common.Constants
import com.eka.conversation.data.local.db.entities.models.MessageRole

Expand All @@ -14,6 +13,7 @@ import com.eka.conversation.data.local.db.entities.models.MessageRole
data class MessageEntity(
@ColumnInfo(name = "msg_id") val msgId : Int,
@ColumnInfo(name = "session_id") val sessionId : String,
@ColumnInfo(name = "session_identity") val sessionIdentity: String? = null,
@ColumnInfo(name = "role") val role : MessageRole,
@ColumnInfo(name = "message_files") val messageFiles : List<Int>? = null,
@ColumnInfo(name = "message_text") val messageText : String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ class ChatRepositoryImpl(
TODO("Not yet implemented")
}

override suspend fun getSessionIdBySessionIdentity(sessionIdentity: String): Response<String?> {
return withContext(Dispatchers.IO) {
try {
val response = chatDatabase.messageDao()
.getSessionIdBySessionIdentity(sessionIdentity = sessionIdentity)
Response.Success(data = response)
} catch (e: Exception) {
Response.Error(message = e.message.toString())
}
}
}

override suspend fun queryPost(queryPostRequest: QueryPostRequest): Flow<QueryResponseEvent> =
flow {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ChatRepository {
suspend fun insertFiles(files : List<MessageFile>)
suspend fun deleteFiles(files : List<MessageFile>) : Response<Boolean>
suspend fun getFileById(fileId : Int) : Response<MessageFile>
suspend fun getSessionIdBySessionIdentity(sessionIdentity: String): Response<String?>

//remote
suspend fun queryPost(queryPostRequest: QueryPostRequest): Flow<QueryResponseEvent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ConversationActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

ChatInit.setChatViewModel(chatViewModel)

setContent {
ConversationScreen(
viewModel = chatViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ import kotlinx.coroutines.delay
fun AudioFileView(
audioFilePath: String,
modifier: Modifier = Modifier,
onRemove: () -> Unit // Callback to remove the file
onRemove: () -> Unit
) {
// State to manage playback
var isPlaying by remember { mutableStateOf(false) }
var currentPosition by remember { mutableLongStateOf(0L) }
var duration by remember { mutableLongStateOf(0L) }
val mediaPlayer = remember { MediaPlayer() }

// Prepare media player when composable is loaded
DisposableEffect(Unit) {
try {
mediaPlayer.setDataSource(audioFilePath)
Expand All @@ -68,7 +66,6 @@ fun AudioFileView(
}
}

// UI Components
Row(
modifier = modifier
.padding(8.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.eka.conversation.ui.presentation.components

import android.content.Context
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -11,22 +10,19 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.isImeVisible
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -35,6 +31,8 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
Expand All @@ -49,7 +47,6 @@ import com.eka.conversation.common.models.ChatInitConfiguration
import com.eka.conversation.features.audio.DefaultAudioProcessor
import com.eka.conversation.ui.presentation.models.BottomSectionConfiguration
import com.eka.conversation.ui.presentation.viewmodels.ChatViewModel
import com.eka.conversation.ui.theme.Gray200

@OptIn(ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -60,11 +57,10 @@ fun ChatScreenBottomSection(
viewModel: ChatViewModel,
bottomSectionConfiguration: BottomSectionConfiguration = BottomSectionConfiguration.defaults()
) {
val listState = rememberLazyListState()
val context = LocalContext.current.applicationContext
val currentTranscribeData by viewModel.currentTranscribeData.collectAsState(Response.Loading())
var textInputState by remember {
mutableStateOf("")
}
var textInputState by viewModel.textInputState
val isKeyboardOpen = WindowInsets.isImeVisible
var isRecording by remember { mutableStateOf(false) }
var recordingTime by remember { mutableStateOf(0) }
Expand All @@ -74,19 +70,19 @@ fun ChatScreenBottomSection(
var audioFilePath by remember {
mutableStateOf("")
}

val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current

LaunchedEffect(Unit) {
focusRequester.requestFocus()
keyboardController?.show()
}

Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
if (audioFilePath.isNotEmpty()) {
AudioFileView(
audioFilePath = audioFilePath
) {
audioFilePath = ""
}
}
Row(
modifier = modifier
.fillMaxWidth()
Expand All @@ -102,10 +98,11 @@ fun ChatScreenBottomSection(
OutlinedTextField(
modifier = chatInputAreaConfig.modifier
.padding(0.dp)
.focusRequester(focusRequester)
.weight(1f),
value = textInputState,
newValue ->
textInputState = newValue
viewModel.updateTextInputState(newValue)
onInputChange(newValue)
},
enabled = !isRecording,
Expand All @@ -132,7 +129,7 @@ fun ChatScreenBottomSection(
.clickable {
if (Utils.isNetworkAvailable(context = context)) {
onQuerySubmit(context, bottomSectionConfiguration)
textInputState = ""
viewModel.updateTextInputState("")
} else {
Toast.makeText(
context,
Expand Down Expand Up @@ -175,7 +172,7 @@ fun ChatScreenBottomSection(
.clickable {
if (Utils.isNetworkAvailable(context = context)) {
onQuerySubmit(context, bottomSectionConfiguration)
textInputState = ""
F438 viewModel.updateTextInputState("")
} else {
Toast.makeText(
context,
Expand Down Expand Up @@ -206,7 +203,7 @@ fun ChatScreenBottomSection(

is Response.Success -> {
val transcribedText = response.data.toString()
textInputState = transcribedText
viewModel.updateTextInputState(transcribedText)
onInputChange(transcribedText)
viewModel.clearRecording()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.eka.conversation.ChatInit
import com.eka.conversation.R
import com.eka.conversation.ui.presentation.models.ThreadsTopBarConfiguration

@Composable
fun ThreadScreenTopBar(
modifier: Modifier = Modifier,
threadsTopBarConfiguration: ThreadsTopBarConfiguration = ThreadsTopBarConfiguration.defaults(),

onBackClick: () -> Unit,
onSearchClick: () -> Unit,
onSortClick: () -> Unit
) {
val chatInitConfig = ChatInit.getChatInitConfiguration()
Column {
Row(
modifier = modifier
Expand All @@ -54,21 +57,23 @@ fun ThreadScreenTopBar(
threadsTopBarConfiguration.subTitle.invoke()
}
}
IconButton(
>
) {
Icon(
painter = painterResource(id = R.drawable.ic_chat_search),
tint = Color.Black,
contentDescription = "Back"
)
if (chatInitConfig.chatGeneralConfiguration.isSearchEnabled) {
IconButton( class="x x-first x-last">) {
Icon(
painter = painterResource(id = R.drawable.ic_chat_search),
tint = Color.Black,
contentDescription = "Back"
)
}
}
IconButton( {
Icon(
painter = painterResource(id = R.drawable.ic_chat_sort),
tint = Color.Black,
contentDescription = "Back"
)
if (chatInitConfig.chatGeneralConfiguration.isSortEnabled) {
IconButton( {
Icon(
painter = painterResource(id = R.drawable.ic_chat_sort),
tint = Color.Black,
contentDescription = "Back"
)
}
}
}
Spacer(
Expand Down
Loading
0