Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/deploymentTargetDropDown.xml
  • Loading branch information
dheshanm committed Apr 10, 2023
2 parents 6ec767f + 8141f0f commit 13953f4
Show file tree
Hide file tree
Showing 41 changed files with 1,165 additions and 222 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
applicationId "com.mohandass.botforge"
minSdk 28
targetSdk 33
versionCode 21
versionName "1.2.1"
versionCode 22
versionName "1.2.2"

vectorDrawables {
useSupportLibrary true
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/mohandass/botforge/AppRoutes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sealed class AppRoutes(val route: String) {
object History : PersonaRoutes("history_persona")
object Marketplace : PersonaRoutes("share_persona")
object Share : PersonaRoutes("create_persona")
object List : PersonaRoutes("list_persona")
}

object Settings : MainRoutes("main_settings")
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/mohandass/botforge/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import com.mohandass.botforge.auth.services.AccountService
import com.mohandass.botforge.chat.services.OpenAiService
import com.mohandass.botforge.chat.services.implementation.ChatServiceImpl
import com.mohandass.botforge.chat.services.implementation.PersonaServiceImpl
import com.mohandass.botforge.chat.viewmodel.ChatViewModel
import com.mohandass.botforge.chat.viewmodel.HistoryViewModel
import com.mohandass.botforge.chat.viewmodel.PersonaViewModel
import com.mohandass.botforge.chat.viewmodel.TopBarViewModel
import com.mohandass.botforge.chat.viewmodel.*
import com.mohandass.botforge.common.services.Logger
import com.mohandass.botforge.common.services.snackbar.SnackbarLauncherLocation
import com.mohandass.botforge.common.services.snackbar.SnackbarManager
Expand Down Expand Up @@ -147,6 +144,14 @@ class AppViewModel @Inject constructor(
val persona: PersonaViewModel
get() = _personaViewModel

private val _personaListViewModel = PersonaListViewModel(
viewModel = this,
botService = botService,
logger = logger
)
val personaList: PersonaListViewModel
get() = _personaListViewModel

// Sync

private val _browseViewModel = BrowseViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.mohandass.botforge.chat.model
*/
enum class ChatType {
CREATE,
LIST,
SHARE,
BROWSE,
CHAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

package com.mohandass.botforge.chat.model.dao.entities

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.mohandass.botforge.common.Samples
import java.util.*

/**
Expand Down Expand Up @@ -40,3 +42,47 @@ data class Persona(
")"
}
}

class PersonaProvider: PreviewParameterProvider<Persona> {
private val shortMessage = Persona(
uuid = UUID.randomUUID().toString(),
parentUuid = UUID.randomUUID().toString(),
name = Samples.name,
alias = Samples.emoji,
systemMessage = Samples.systemMessage2,
createdAt = System.currentTimeMillis(),
lastUsed = System.currentTimeMillis(),
)

private val community = Persona(
uuid = UUID.randomUUID().toString(),
parentUuid = UUID.randomUUID().toString(),
name = Samples.name,
alias = Samples.emoji,
systemMessage = Samples.systemMessage,
createdAt = System.currentTimeMillis(),
lastUsed = System.currentTimeMillis(),
)

private val default = Persona(
uuid = UUID.randomUUID().toString(),
parentUuid = "",
name = Samples.name,
alias = Samples.emoji,
systemMessage = Samples.systemMessage,
createdAt = System.currentTimeMillis(),
lastUsed = System.currentTimeMillis(),
)

private val longName = Persona(
uuid = UUID.randomUUID().toString(),
parentUuid = UUID.randomUUID().toString(),
name = Samples.name + Samples.name + Samples.name + Samples.name + Samples.name,
alias = Samples.emoji,
systemMessage = Samples.systemMessage,
createdAt = System.currentTimeMillis(),
lastUsed = System.currentTimeMillis(),
)

override val values: Sequence<Persona> = sequenceOf(shortMessage, community, default, longName)
}
26 changes: 20 additions & 6 deletions app/src/main/java/com/mohandass/botforge/chat/ui/ChatUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.unit.dp
import com.mohandass.botforge.AppViewModel
import com.mohandass.botforge.chat.model.ChatType
import com.mohandass.botforge.chat.ui.components.chat.CustomisePersona
import com.mohandass.botforge.chat.ui.components.chat.SendFloatingActionButton
import com.mohandass.botforge.chat.ui.components.chat.headers.CustomisePersonaHeader
Expand All @@ -35,6 +36,7 @@ import com.mohandass.botforge.common.services.snackbar.SnackbarManager
import com.mohandass.botforge.common.services.snackbar.SwipeableSnackbarHost
import com.mohandass.botforge.rememberSnackbarLauncher
import com.mohandass.botforge.sync.ui.components.BotDetailDialog
import com.mohandass.botforge.sync.ui.components.BotDetailDialogConfig
import com.slaviboy.composeunits.adh

// Main Chat UI, with Customise Persona and Messages
Expand Down Expand Up @@ -64,6 +66,14 @@ fun ChatUi(viewModel: AppViewModel) {
mutableStateOf(false)
}

LaunchedEffect(Unit) {
if (viewModel.persona.selectedPersona.value == "") {
viewModel.persona.setChatType(ChatType.CREATE)
} else {
viewModel.persona.setChatType(ChatType.CHAT)
}
}

val userPreferences by viewModel.userPreferences.observeAsState()
userPreferences?.let {
isUserGeneratedContentEnabled = it.enableUserGeneratedContent
Expand All @@ -72,18 +82,22 @@ fun ChatUi(viewModel: AppViewModel) {
// Show bot detail dialog for Bots from Community
if (showDetailDialog.value) {
parentBot?.let {
val botDetailDialogConfig = BotDetailDialogConfig(
bot = it,
onUpVote = {
viewModel.browse.upVote(it.uuid)
},
onDownVote = { viewModel.browse.downVote(it.uuid) },
onReport = { viewModel.browse.report(it.uuid) },
)

BotDetailDialog(
it,
showAdd = false,
onClickDismiss = { showDetailDialog.value = false },
onClickAccept = {
showDetailDialog.value = false
},
onUpVote = {
viewModel.browse.upVote(it.uuid)
},
onDownVote = { viewModel.browse.downVote(it.uuid) },
onReport = { viewModel.browse.report(it.uuid) },
config = botDetailDialogConfig
)
}
}
Expand Down
76 changes: 19 additions & 57 deletions app/src/main/java/com/mohandass/botforge/chat/ui/HistoryUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ package com.mohandass.botforge.chat.ui
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.*
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.mohandass.botforge.AppViewModel
import com.mohandass.botforge.R
import com.mohandass.botforge.chat.model.ChatType
import com.mohandass.botforge.chat.ui.components.ChatCard
import com.mohandass.botforge.chat.ui.components.ImageWithMessage
import com.mohandass.botforge.chat.ui.components.dialogs.DeleteHistoryDialog
import com.mohandass.botforge.chat.ui.components.header.HeaderWithActionIcon

@Composable
fun HistoryUi(viewModel: AppViewModel) {
Expand All @@ -43,6 +44,7 @@ fun HistoryUi(viewModel: AppViewModel) {
val personas = viewModel.persona.personas

LaunchedEffect(Unit) {
viewModel.persona.setChatType(ChatType.HISTORY)
viewModel.history.fetchChats(onSuccess = {})
}

Expand All @@ -61,66 +63,26 @@ fun HistoryUi(viewModel: AppViewModel) {
.padding(10.dp)
) {

Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = painterResource(id = R.drawable.baseline_bookmarks_24),
contentDescription = stringResource(id = R.string.bookmarks),
modifier = Modifier
)
Text(
text = stringResource(id = R.string.bookmarked),
modifier = Modifier.padding(10.dp),
style = MaterialTheme.typography.headlineSmall
)

Spacer(modifier = Modifier.weight(1f))

// Clear all button
IconButton(onClick = {
HeaderWithActionIcon(
text = stringResource(id = R.string.bookmarked),
leadingIcon = painterResource(id = R.drawable.baseline_bookmarks_24),
leadingIconContentDescription = stringResource(id = R.string.bookmarks),
trailingIcon = painterResource(id = R.drawable.baseline_clear_all_24),
trailingIconContentDescription = stringResource(id = R.string.clear_all_cd),
trailingIconOnClick = {
viewModel.history.updateDeleteDialogState(true)
}) {
Icon(
painter = painterResource(id = R.drawable.baseline_clear_all_24),
contentDescription = stringResource(id = R.string.clear_all_cd),
tint = MaterialTheme.colorScheme.error
)
}
}
)

Spacer(modifier = Modifier.height(10.dp))

// Show empty box if no chats are bookmarked yet
if (chats.isEmpty()) {
Box(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier.align(Alignment.Center),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Icon(
painterResource(id = R.drawable.empty_box),
modifier = Modifier
.size(150.dp)
.alpha(0.8f),
contentDescription = stringResource(id = R.string.no_bookmarks_cd)
)

Spacer(modifier = Modifier.height(24.dp))

Text(
text = stringResource(id = R.string.no_bookmarks),
style = MaterialTheme.typography.bodyLarge
)

Spacer(modifier = Modifier.height(24.dp))
}
}
}
ImageWithMessage(
visible = chats.isEmpty(),
painter = painterResource(id = R.drawable.empty_box),
imageContentDescription = stringResource(id = R.string.no_bookmarks_cd),
message = stringResource(id = R.string.no_bookmarks),
)

// Show chats, if any, are bookmarked
LazyColumn(
Expand Down
Loading

0 comments on commit 13953f4

Please sign in to comment.