Skip to content

Commit

Permalink
refactor: Improved Studio Bot, code readability, and extensions
Browse files Browse the repository at this point in the history
Enhanced Studio Bot functionality and code quality:

- Updated Studio Bot with new system instructions for improved performance and accuracy.
- Refactored code for better readability and maintainability.
- Improved the functionality and efficiency of existing extensions.
- Removed unused code and variables to streamline the project.
- Upgraded the Studio Bot model from Gemini 1.0 Pro to 1.5 Pro for enhanced capabilities.
  • Loading branch information
Mihai-Cristian Condrea committed Dec 24, 2024
1 parent 2ebbb0d commit a7f1f1f
Show file tree
Hide file tree
Showing 66 changed files with 366 additions and 355 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
- **New**: Refactored the UI structure to enhance organization and maintainability.
- **New**: Added "Like" and "Dislike" feedback for Studio Bot messages.
- **New**: Introduced new profile pictures for Studio Bot and user messages.
- **New**: Updated Studio Bot with new system instructions for improved performance and accuracy.
- **Major**: Upgraded the Studio Bot model from Gemini 1.0 Pro to 1.5 Pro for enhanced capabilities.
- **Minor**: Updated the Help screen UI for better UX.
- **Minor**: Improved the placement of the copy button in Studio Bot chat bubbles.
- **Minor**: Optimized keyboard behavior on the Studio Bot screen.
- **Patch**: Standardized naming of `packageName` for consistency.
- **Patch**: Removed unused Gradle dependencies to streamline the build process.
- **Patch**: Refactored code for better readability and maintainability.
- **Patch**: Improved the functionality and efficiency of existing extensions.
- **Patch**: Updated project dependencies to the latest stable versions.
- **Patch**: Corrected the string used for "Security & Privacy" title on the Privacy screen.
- **Patch**: Removed unused Data Store constants from the codebase.
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
applicationId = "com.d4rk.androidtutorials"
minSdk = 23
targetSdk = 35
versionCode = 92
versionCode = 93
versionName = "1.1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
resourceConfigurations += listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.d4rk.androidtutorials.data.core.ads

import android.app.Activity
import android.content.Context
import com.d4rk.androidtutorials.constants.ads.AdsConstants
import com.d4rk.androidtutorials.utils.constants.ads.AdsConstants
import com.d4rk.androidtutorials.data.datastore.DataStore
import com.d4rk.androidtutorials.utils.interfaces.OnShowAdCompleteListener
import com.google.android.gms.ads.AdError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.d4rk.androidtutorials.data.core.datastore

import android.content.Context
import com.d4rk.androidtutorials.constants.ui.bottombar.BottomBarRoutes
import com.d4rk.androidtutorials.utils.constants.ui.bottombar.BottomBarRoutes
import com.d4rk.androidtutorials.data.datastore.DataStore
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.d4rk.androidtutorials.BuildConfig
import com.d4rk.androidtutorials.constants.datastore.DataStoreNamesConstants
import com.d4rk.androidtutorials.constants.ui.bottombar.BottomBarRoutes
import com.d4rk.androidtutorials.utils.constants.datastore.DataStoreNamesConstants
import com.d4rk.androidtutorials.utils.constants.ui.bottombar.BottomBarRoutes
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ data class ApiLessonContent(
@SerialName("content_text") val contentText : String = "" ,
@SerialName("content_code") val contentCode : String = "" ,
@SerialName("content_code_programming_language") val programmingLanguage : String = "" ,
@SerialName("content_image_src") val contentImageSrc : String = "" ,
@SerialName("content_image_url") val contentImageUrl : String = "" ,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.material.icons.sharp.AutoAwesome
import androidx.compose.material.icons.sharp.FavoriteBorder
import androidx.compose.ui.graphics.vector.ImageVector
import com.d4rk.androidtutorials.R
import com.d4rk.androidtutorials.constants.ui.bottombar.BottomBarRoutes
import com.d4rk.androidtutorials.utils.constants.ui.bottombar.BottomBarRoutes

sealed class BottomNavigationScreen(
val route : String , val icon : ImageVector , val selectedIcon : ImageVector , val title : Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ data class UiLessonContent(
val contentText : String = "" ,
val contentCode : String = "" ,
val programmingLanguage : String = "" ,
val contentImageSrc : String = ""
val contentImageUrl : String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import com.d4rk.androidtutorials.data.model.ui.navigation.BottomNavigationScreen

data class UiMainScreen(
val currentBottomNavigationScreen : BottomNavigationScreen = BottomNavigationScreen.Home ,
val trashSize : String = "0 KB" ,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import com.d4rk.androidtutorials.constants.ads.AdsConstants
import com.d4rk.androidtutorials.utils.constants.ads.AdsConstants
import com.d4rk.androidtutorials.data.datastore.DataStore
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.androidtutorials.R
import com.d4rk.androidtutorials.constants.ui.bottombar.BottomBarRoutes
import com.d4rk.androidtutorials.utils.constants.ui.bottombar.BottomBarRoutes
import com.d4rk.androidtutorials.data.datastore.DataStore
import kotlinx.coroutines.flow.firstOrNull

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import coil3.ImageLoader
import coil3.compose.AsyncImage
import coil3.gif.AnimatedImageDecoder
import coil3.gif.GifDecoder
import com.d4rk.androidtutorials.constants.ui.lessons.LessonCodeConstants
import com.d4rk.androidtutorials.constants.ui.lessons.LessonContentTypes
import com.d4rk.androidtutorials.utils.constants.ui.lessons.LessonCodeConstants
import com.d4rk.androidtutorials.utils.constants.ui.lessons.LessonContentTypes
import com.d4rk.androidtutorials.data.datastore.DataStore
import com.d4rk.androidtutorials.data.model.ui.screens.UiLessonScreen
import com.d4rk.androidtutorials.ui.components.ads.AdBanner
Expand All @@ -54,9 +54,10 @@ import com.d4rk.androidtutorials.ui.components.ads.LargeBannerAdsComposable
import com.d4rk.androidtutorials.ui.components.modifiers.bounceClick
import com.d4rk.androidtutorials.ui.screens.settings.display.theme.style.Colors
import com.d4rk.androidtutorials.ui.screens.settings.display.theme.style.TextStyles
import com.d4rk.androidtutorials.utils.ClipboardUtil
import com.d4rk.androidtutorials.utils.helpers.ClipboardHelper
import com.wakaztahir.codeeditor.highlight.model.CodeLang
import com.wakaztahir.codeeditor.highlight.prettify.PrettifyParser
import com.wakaztahir.codeeditor.highlight.theme.CodeTheme
import com.wakaztahir.codeeditor.highlight.theme.CodeThemeType
import com.wakaztahir.codeeditor.highlight.utils.parseCodeAsAnnotatedString

Expand All @@ -70,9 +71,9 @@ fun LessonContentLayout(
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
.padding(paddingValues = paddingValues)
.padding(horizontal = 16.dp)
.verticalScroll(scrollState)
.verticalScroll(state = scrollState)
) {
lesson.lessonContent.forEachIndexed { index , contentItem ->
when (contentItem.contentType) {
Expand All @@ -94,7 +95,7 @@ fun LessonContentLayout(

LessonContentTypes.IMAGE -> {
StyledImage(
imageUrl = contentItem.contentImageSrc , contentDescription = "Lesson Image"
imageUrl = contentItem.contentImageUrl , contentDescription = "Lesson Image"
)
}

Expand All @@ -121,7 +122,7 @@ fun LessonContentLayout(
}
}
if (index < lesson.lessonContent.lastIndex) {
Spacer(modifier = Modifier.height(8.dp))
Spacer(modifier = Modifier.height(height = 8.dp))
}
}
}
Expand All @@ -133,7 +134,7 @@ fun StyledText(
style : TextStyle = TextStyles.body() ,
color : Color = Colors.primaryText() ,
) {
val annotatedString = AnnotatedString.fromHtml(text)
val annotatedString = AnnotatedString.fromHtml(htmlString = text)

Text(
text = annotatedString , style = style , color = color
Expand All @@ -147,12 +148,12 @@ fun StyledImage(
modifier : Modifier = Modifier ,
) {
val context : Context = LocalContext.current
val imageLoader = ImageLoader.Builder(context).components {
val imageLoader = ImageLoader.Builder(context = context).components {
if (SDK_INT >= 28) {
add(AnimatedImageDecoder.Factory())
add(factory = AnimatedImageDecoder.Factory())
}
else {
add(GifDecoder.Factory())
add(factory = GifDecoder.Factory())
}
}.build()
Card(
Expand Down Expand Up @@ -321,13 +322,13 @@ fun CodeBlock(code : String , language : String?) {
}
}

val parser = remember { PrettifyParser() }
val themeState by remember { mutableStateOf(CodeThemeType.Default) }
val theme = remember(themeState) { themeState.theme() }
val parser : PrettifyParser = remember { PrettifyParser() }
val themeState : CodeThemeType by remember { mutableStateOf(value = CodeThemeType.Default) }
val theme : CodeTheme = remember(key1 = themeState) { themeState.theme() }

val textFieldValue by remember {
val textFieldValue : TextFieldValue by remember {
mutableStateOf(
TextFieldValue(
value = TextFieldValue(
annotatedString = parseCodeAsAnnotatedString(
parser = parser , theme = theme , lang = lang , code = code
)
Expand All @@ -352,27 +353,28 @@ fun CodeBlock(code : String , language : String?) {
modifier = Modifier.padding(end = 8.dp)
)
TextButton(modifier = Modifier.bounceClick() , onClick = {
ClipboardUtil.copyTextToClipboard(context = context ,
label = "Code" ,
text = code ,
onShowSnackbar = {
Toast.makeText(
context ,
"Code copied to clipboard" ,
Toast.LENGTH_SHORT
).show()
})
ClipboardHelper.copyTextToClipboard(
context = context ,
label = "Code" ,
text = code ,
onShowSnackbar = {
Toast.makeText(
context ,
"Code copied to clipboard" ,
Toast.LENGTH_SHORT
).show()
})
} , contentPadding = PaddingValues(horizontal = 8.dp)) {
Icon(
imageVector = Icons.Outlined.CopyAll ,
contentDescription = "Copy Code" ,
modifier = Modifier.size(ButtonDefaults.IconSize)
modifier = Modifier.size(size = ButtonDefaults.IconSize)
)
Spacer(modifier = Modifier.width(ButtonDefaults.IconSpacing))
Spacer(modifier = Modifier.width(width = ButtonDefaults.IconSpacing))
Text(text = stringResource(id = android.R.string.copy))
}
}
Spacer(modifier = Modifier.height(2.dp))
Spacer(modifier = Modifier.height(height = 2.dp))
SelectionContainer {
Text(
text = textFieldValue.annotatedString ,
Expand All @@ -381,7 +383,7 @@ fun CodeBlock(code : String , language : String?) {
.padding(horizontal = 8.dp)
)
}
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(height = 16.dp))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import coil3.compose.AsyncImage
import com.d4rk.androidtutorials.constants.ui.lessons.LessonConstants
import com.d4rk.androidtutorials.utils.constants.ui.lessons.LessonConstants
import com.d4rk.androidtutorials.data.model.ui.screens.UiHomeLesson
import com.d4rk.androidtutorials.ui.components.modifiers.animateVisibility
import com.d4rk.androidtutorials.ui.components.modifiers.bounceClick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.d4rk.androidtutorials.R

@Composable
fun NoLessonsScreen(
text : String = "No lessons found." ,
text : Int = R.string.lesson_not_found ,
icon : ImageVector = Icons.Default.Info ,
iconDescription : String = "No lessons icon"
) {
Box(
modifier = Modifier
.fillMaxSize()
.wrapContentSize(Alignment.Center)
.wrapContentSize(align = Alignment.Center)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally ,
Expand All @@ -38,12 +40,12 @@ fun NoLessonsScreen(
imageVector = icon ,
contentDescription = iconDescription ,
modifier = Modifier
.size(58.dp)
.size(size = 58.dp)
.padding(bottom = 16.dp) ,
tint = MaterialTheme.colorScheme.primary
)
Text(
text = text ,
text = stringResource(id = text) ,
style = MaterialTheme.typography.displaySmall.copy(textAlign = TextAlign.Center) ,
color = MaterialTheme.colorScheme.onBackground
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.compose.currentBackStackEntryAsState
import com.d4rk.androidtutorials.data.datastore.DataStore
import com.d4rk.androidtutorials.data.model.ui.navigation.BottomNavigationScreen
import com.d4rk.androidtutorials.ui.components.ads.AdBannerFull
import com.d4rk.androidtutorials.ui.components.modifiers.bounceClick

@Composable
fun BottomNavigationBar(
navController : NavController , dataStore : DataStore , view : View
navController : NavController ,
dataStore : DataStore ,
view : View ,
currentScreen : BottomNavigationScreen ,
onScreenSelected : (BottomNavigationScreen) -> Unit
) {
val bottomBarItems : List<BottomNavigationScreen> = listOf(
BottomNavigationScreen.Home ,
Expand All @@ -41,12 +42,10 @@ fun BottomNavigationBar(
modifier = Modifier.fillMaxWidth() , dataStore = dataStore
)
NavigationBar {
val navBackStackEntry : NavBackStackEntry? by navController.currentBackStackEntryAsState()
val currentRoute : String? = navBackStackEntry?.destination?.route
bottomBarItems.forEach { screen ->
NavigationBarItem(icon = {
val iconResource : ImageVector =
if (currentRoute == screen.route) screen.selectedIcon else screen.icon
if (currentScreen == screen) screen.selectedIcon else screen.icon
Icon(
imageVector = iconResource ,
modifier = Modifier.bounceClick() ,
Expand All @@ -58,9 +57,10 @@ fun BottomNavigationBar(
overflow = TextOverflow.Ellipsis ,
modifier = Modifier.basicMarquee()
)
} , selected = currentRoute == screen.route , onClick = {
} , selected = currentScreen == screen , onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
if (currentRoute != screen.route) {
if (currentScreen != screen) {
onScreenSelected(screen)
navController.navigate(screen.route) {
popUpTo(navController.graph.startDestinationId) {
saveState = false
Expand Down
Loading

0 comments on commit a7f1f1f

Please sign in to comment.