Skip to content

Commit 5391b0c

Browse files
committed
ui: improve chats list drawer
- add a marker to indicate currently selected chat - remove 'bubble' layout for each chat item - replace 'previous chats' with 'chats' - increase the font size of chat title in the list
1 parent f296c8f commit 5391b0c

File tree

4 files changed

+75
-34
lines changed

4 files changed

+75
-34
lines changed

app/src/main/java/io/shubham0204/smollmandroid/ui/screens/chat/ChatActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import androidx.compose.foundation.text.KeyboardOptions
5555
import androidx.compose.material.icons.Icons
5656
import androidx.compose.material.icons.automirrored.filled.ArrowForward
5757
import androidx.compose.material.icons.filled.Android
58-
import androidx.compose.material.icons.filled.Menu
58+
import androidx.compose.material.icons.filled.DragHandle
5959
import androidx.compose.material.icons.filled.MoreVert
6060
import androidx.compose.material.icons.filled.Stop
6161
import androidx.compose.material3.CircularProgressIndicator
@@ -253,7 +253,7 @@ fun ChatActivityScreenUI(
253253
navigationIcon = {
254254
IconButton(onClick = { scope.launch { drawerState.open() } }) {
255255
Icon(
256-
Icons.Default.Menu,
256+
Icons.Default.DragHandle,
257257
contentDescription = stringResource(R.string.chat_view_chats),
258258
)
259259
}

app/src/main/java/io/shubham0204/smollmandroid/ui/screens/chat/ChatListDrawer.kt

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.text.format.DateUtils
2020
import androidx.compose.foundation.background
2121
import androidx.compose.foundation.clickable
2222
import androidx.compose.foundation.layout.Arrangement
23+
import androidx.compose.foundation.layout.Box
2324
import androidx.compose.foundation.layout.Column
2425
import androidx.compose.foundation.layout.ColumnScope
2526
import androidx.compose.foundation.layout.Row
@@ -30,11 +31,13 @@ import androidx.compose.foundation.layout.fillMaxWidth
3031
import androidx.compose.foundation.layout.height
3132
import androidx.compose.foundation.layout.padding
3233
import androidx.compose.foundation.layout.requiredWidth
33-
import androidx.compose.foundation.layout.safeContent
34+
import androidx.compose.foundation.layout.safeDrawing
35+
import androidx.compose.foundation.layout.size
3436
import androidx.compose.foundation.layout.windowInsetsPadding
3537
import androidx.compose.foundation.lazy.LazyColumn
3638
import androidx.compose.foundation.lazy.LazyItemScope
3739
import androidx.compose.foundation.lazy.items
40+
import androidx.compose.foundation.shape.CircleShape
3841
import androidx.compose.foundation.shape.RoundedCornerShape
3942
import androidx.compose.material.icons.Icons
4043
import androidx.compose.material.icons.filled.Add
@@ -48,10 +51,12 @@ import androidx.compose.material3.Text
4851
import androidx.compose.runtime.Composable
4952
import androidx.compose.runtime.collectAsState
5053
import androidx.compose.runtime.getValue
54+
import androidx.compose.runtime.setValue
5155
import androidx.compose.ui.Alignment
5256
import androidx.compose.ui.Modifier
5357
import androidx.compose.ui.draw.clip
5458
import androidx.compose.ui.res.stringResource
59+
import androidx.compose.ui.text.style.TextOverflow
5560
import androidx.compose.ui.unit.dp
5661
import io.shubham0204.smollmandroid.R
5762
import io.shubham0204.smollmandroid.data.Chat
@@ -69,30 +74,60 @@ fun DrawerUI(
6974
modifier =
7075
Modifier
7176
.background(MaterialTheme.colorScheme.surfaceContainer)
72-
.windowInsetsPadding(WindowInsets.safeContent)
77+
.windowInsetsPadding(WindowInsets.safeDrawing)
7378
.padding(8.dp)
7479
.requiredWidth(300.dp)
7580
.fillMaxHeight(),
7681
) {
77-
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly) {
82+
Row(
83+
modifier = Modifier.fillMaxWidth(),
84+
horizontalArrangement = Arrangement.SpaceEvenly,
85+
) {
7886
Button(
7987
onClick = {
8088
val chatCount = viewModel.chatsDB.getChatsCount()
81-
val newChat = viewModel.chatsDB.addChat(chatName = "Untitled ${chatCount + 1}")
89+
val newChat =
90+
viewModel.chatsDB.addChat(chatName = "Untitled ${chatCount + 1}")
8291
onItemClick(newChat)
8392
},
8493
) {
8594
Icon(Icons.Default.Add, contentDescription = "New Chat")
86-
Text(stringResource(R.string.chat_drawer_new_chat), style = MaterialTheme.typography.labelMedium)
95+
Text(
96+
stringResource(R.string.chat_drawer_new_chat),
97+
style = MaterialTheme.typography.labelMedium,
98+
)
8799
}
88100
Button(
89101
onClick = onCreateTaskClick,
90102
) {
91103
Icon(Icons.Default.AddTask, contentDescription = "New Task")
92-
Text(stringResource(R.string.chat_drawer_new_task), style = MaterialTheme.typography.labelMedium)
104+
Text(
105+
stringResource(R.string.chat_drawer_new_task),
106+
style = MaterialTheme.typography.labelMedium,
107+
)
93108
}
94109
}
95110
Spacer(modifier = Modifier.height(16.dp))
111+
ChatsList(
112+
viewModel,
113+
onManageTasksClick,
114+
onItemClick,
115+
)
116+
}
117+
AppAlertDialog()
118+
}
119+
}
120+
121+
@Composable
122+
private fun ColumnScope.ChatsList(
123+
viewModel: ChatScreenViewModel,
124+
onManageTasksClick: () -> Unit,
125+
onItemClick: (Chat) -> Unit,
126+
) {
127+
val chats by viewModel.getChats().collectAsState(emptyList())
128+
val currentChat by viewModel.currChatState.collectAsState(null)
129+
LazyColumn(modifier = Modifier.weight(1f)) {
130+
item {
96131
Row(
97132
modifier =
98133
Modifier
@@ -120,49 +155,55 @@ fun DrawerUI(
120155
style = MaterialTheme.typography.labelSmall,
121156
)
122157
Spacer(modifier = Modifier.height(8.dp))
123-
ChatsList(viewModel, onItemClick)
124158
}
125-
AppAlertDialog()
126-
}
127-
}
128-
129-
@Composable
130-
private fun ColumnScope.ChatsList(
131-
viewModel: ChatScreenViewModel,
132-
onItemClick: (Chat) -> Unit,
133-
) {
134-
val chats by viewModel.getChats().collectAsState(emptyList())
135-
LazyColumn(modifier = Modifier.weight(1f)) {
136-
items(chats) { chat -> ChatListItem(chat, onItemClick) }
159+
items(chats) { chat ->
160+
ChatListItem(
161+
chat,
162+
onItemClick,
163+
currentChat?.id == chat.id,
164+
)
165+
}
137166
}
138167
}
139168

140169
@Composable
141170
private fun LazyItemScope.ChatListItem(
142171
chat: Chat,
143172
onItemClick: (Chat) -> Unit,
173+
isCurrentlySelected: Boolean,
144174
) {
145175
Row(
146176
modifier =
147177
Modifier
148178
.fillMaxWidth()
149-
.padding(4.dp)
150-
.background(MaterialTheme.colorScheme.surfaceContainerHighest, RoundedCornerShape(8.dp))
151179
.padding(8.dp)
152180
.clip(RoundedCornerShape(8.dp))
153181
.clickable { onItemClick(chat) }
154182
.animateItem(),
155183
verticalAlignment = Alignment.CenterVertically,
156184
) {
157-
Column(modifier = Modifier.weight(1f)) {
158-
Text(
159-
chat.name,
160-
style = MaterialTheme.typography.labelLarge,
161-
)
162-
Text(
163-
text = DateUtils.getRelativeTimeSpanString(chat.dateUsed.time).toString(),
164-
style = MaterialTheme.typography.labelMedium,
165-
)
185+
Row(verticalAlignment = Alignment.CenterVertically) {
186+
Column(modifier = Modifier.weight(1f)) {
187+
Text(
188+
chat.name,
189+
style = MaterialTheme.typography.bodyLarge,
190+
maxLines = 1,
191+
overflow = TextOverflow.Ellipsis,
192+
)
193+
Text(
194+
text = DateUtils.getRelativeTimeSpanString(chat.dateUsed.time).toString(),
195+
style = MaterialTheme.typography.labelSmall,
196+
)
197+
}
198+
if (isCurrentlySelected) {
199+
Box(
200+
modifier =
201+
Modifier
202+
.padding(start = 4.dp)
203+
.background(MaterialTheme.colorScheme.tertiary, CircleShape)
204+
.size(10.dp),
205+
) { }
206+
}
166207
}
167208
}
168209
}

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<string name="chat_drawer_new_chat">新建聊天</string>
3333
<string name="chat_drawer_new_task">新建任务</string>
3434
<string name="chat_drawer_manage_tasks">管理任务</string>
35-
<string name="chat_drawer_previous_chat">之前的聊天</string>
35+
<string name="chat_drawer_previous_chat">聊天</string>
3636
<string name="chat_options_edit_settings">编辑聊天设置</string>
3737
<string name="chat_options_change_model">更改模型</string>
3838
<string name="chat_options_ctx_length_usage">上下文长度使用情况</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<string name="chat_drawer_new_chat">New Chat</string>
1818
<string name="chat_drawer_new_task">New Task</string>
1919
<string name="chat_drawer_manage_tasks">Manage Tasks</string>
20-
<string name="chat_drawer_previous_chat">Previous Chats</string>
20+
<string name="chat_drawer_previous_chat">Chats</string>
2121
<string name="chat_options_edit_settings">Edit Chat Settings</string>
2222
<string name="chat_options_change_model">Change Model</string>
2323
<string name="chat_options_ctx_length_usage">Context Length Usage</string>

0 commit comments

Comments
 (0)