Skip to content

Add change theme function: click the sun icon #6

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
Apr 21, 2023
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
31 changes: 19 additions & 12 deletions app/src/main/java/com/chatgptlite/wanted/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class MainActivity : ComponentActivity() {
focusManager.clearFocus()
}
}

ChatGPTLiteTheme() {
val darkTheme = remember(key1 = "darkTheme") {
mutableStateOf(true)
}
ChatGPTLiteTheme(darkTheme.value) {
Surface(
color = MaterialTheme.colorScheme.background,
) {
Expand All @@ -79,18 +81,23 @@ class MainActivity : ComponentActivity() {
scope.launch {
drawerState.close()
}
},
onIconClicked = {
darkTheme.value = !darkTheme.value
}
) {
Column( modifier = Modifier
.fillMaxSize()) {
AppBar (onClickMenu = {
scope.launch {
drawerState.open()
}
})
Divider()
Conversation()
}
Column(
modifier = Modifier
.fillMaxSize()
) {
AppBar(onClickMenu = {
scope.launch {
drawerState.open()
}
})
Divider()
Conversation()
}
}
}
}
Expand Down
73 changes: 46 additions & 27 deletions app/src/main/java/com/chatgptlite/wanted/ui/common/AppDrawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ package com.chatgptlite.wanted.ui.common
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsTopHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -13,7 +27,11 @@ import androidx.compose.material.icons.filled.Message
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.WbSunny
import androidx.compose.material.icons.outlined.AddComment
import androidx.compose.material3.*
import androidx.compose.material3.Divider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -38,47 +56,47 @@ import com.chatgptlite.wanted.constants.urlToImageAuthor
import com.chatgptlite.wanted.helpers.UrlLauncher
import com.chatgptlite.wanted.models.ConversationModel
import com.chatgptlite.wanted.ui.conversations.ConversationViewModel
import com.chatgptlite.wanted.ui.theme.ChatGPTLiteTheme
import kotlinx.coroutines.launch

@Composable
fun AppDrawer(
onChatClicked: (String) -> Unit,
onNewChatClicked: () -> Unit,
conversationViewModel: ConversationViewModel = hiltViewModel(),
onIconClicked: () -> Unit = {}
) {
val context = LocalContext.current

ChatGPTLiteTheme() {
Column(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
Column(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
) {
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.statusBars))
DrawerHeader(clickAction = onIconClicked)
DividerItem()
DrawerItemHeader("Chats")
ChatItem("New Chat", Icons.Outlined.AddComment, false) {
onNewChatClicked()
conversationViewModel.newConversation()
}
HistoryConversations(onChatClicked)
DividerItem(modifier = Modifier.padding(horizontal = 28.dp))
DrawerItemHeader("Settings")
ChatItem("Settings", Icons.Filled.Settings, false) { onChatClicked("Settings") }
ProfileItem(
"lambiengcode (author)",
urlToImageAuthor,
) {
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.statusBars))
DrawerHeader()
DividerItem()
DrawerItemHeader("Chats")
ChatItem("New Chat", Icons.Outlined.AddComment, false) {
onNewChatClicked()
conversationViewModel.newConversation()
}
HistoryConversations(onChatClicked)
DividerItem(modifier = Modifier.padding(horizontal = 28.dp))
DrawerItemHeader("Settings")
ChatItem("Settings", Icons.Filled.Settings, false) { onChatClicked("Settings") }
ProfileItem(
"lambiengcode (author)",
urlToImageAuthor,
) {
UrlLauncher().openUrl(context = context, urlToGithub)
}
UrlLauncher().openUrl(context = context, urlToGithub)
}
}
}

@Composable
private fun DrawerHeader() {
private fun DrawerHeader(
clickAction: () -> Unit = {}
) {
val paddingSizeModifier = Modifier
.padding(start = 16.dp, top = 16.dp, bottom = 16.dp)
.size(34.dp)
Expand Down Expand Up @@ -113,6 +131,7 @@ private fun DrawerHeader() {

IconButton(
onClick = {
clickAction.invoke()
},
) {
Icon(
Expand Down
31 changes: 15 additions & 16 deletions app/src/main/java/com/chatgptlite/wanted/ui/common/AppScaffold.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.hilt.navigation.compose.hiltViewModel
import com.chatgptlite.wanted.ui.conversations.ConversationViewModel
import com.chatgptlite.wanted.ui.theme.BackGroundColor
import com.chatgptlite.wanted.ui.theme.ChatGPTLiteTheme
import kotlinx.coroutines.launch

//import androidx.compose.material3.ModalDrawerSheet

@SuppressLint("CoroutineCreationDuringComposition")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppScaffold (
fun AppScaffold(
drawerState: DrawerState = rememberDrawerState(initialValue = Closed),
onChatClicked: (String) -> Unit,
onNewChatClicked: () -> Unit,
onIconClicked: () -> Unit = {},
conversationViewModel: ConversationViewModel = hiltViewModel(),
content: @Composable () -> Unit,
) {
Expand All @@ -29,19 +29,18 @@ fun AppScaffold (
conversationViewModel.initialize()
}

ModalNavigationDrawer(
drawerState = drawerState,
drawerContent = {
ModalDrawerSheet(drawerContainerColor = BackGroundColor) {
AppDrawer(
onChatClicked = onChatClicked,
onNewChatClicked = onNewChatClicked,
onIconClicked = onIconClicked,
)
}
},
content = content
)

ChatGPTLiteTheme() {
ModalNavigationDrawer(
drawerState = drawerState,
drawerContent = {
ModalDrawerSheet (drawerContainerColor = BackGroundColor) {
AppDrawer (
onChatClicked = onChatClicked,
onNewChatClicked = onNewChatClicked,
)
}
},
content = content
)
}
}