Skip to content

Commit

Permalink
Merge pull request #237 from mhss1/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mhss1 authored Oct 8, 2024
2 parents 8b68b02 + 85855d3 commit b99aa67
Show file tree
Hide file tree
Showing 67 changed files with 944 additions and 894 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ local.properties
/app/release
/.idea/appInsightsSettings.xml
/.kotlin/
/.idea/studiobot.xml
/.idea/runConfigurations.xml
/.idea/gradle.xml
/.idea/compiler.xml
6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

58 changes: 0 additions & 58 deletions .idea/gradle.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fun AssistantScreen(
) {
val context = LocalContext.current
val uiState = viewModel.uiState
val messages = uiState.messages
val messages = viewModel.messages
val loading = uiState.loading
val error = uiState.error
var text by rememberSaveable { mutableStateOf("") }
Expand Down Expand Up @@ -169,11 +169,12 @@ fun AssistantScreen(
LeftToRight {
LazyColumn(
state = lazyListState,
reverseLayout = true
reverseLayout = true,
modifier = Modifier.fillMaxSize()
) {
item(key = 1) { Spacer(Modifier.height(20.dp)) }
item(key = -1) { Spacer(Modifier.height(20.dp)) }
error?.let { error ->
item(key = 2) {
item(key = -2) {
Card(
shape = RoundedCornerShape(18.dp),
border = BorderStroke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import kotlinx.coroutines.launch
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.koin.android.annotation.KoinViewModel
import java.util.LinkedList

@KoinViewModel
class AssistantViewModel(
Expand All @@ -57,12 +56,11 @@ class AssistantViewModel(
private val getTaskById: GetTaskByIdUseCase,
) : ViewModel() {

private val messages = ArrayList<AiMessage>()

private val _messages = mutableStateListOf<AiMessage>()
val messages: List<AiMessage> = _messages
val attachments = mutableStateListOf<AiMessageAttachment>()

// LinkedList to enable inserting at the beginning of the list efficiently
// LazyColumn needs the list in reverse order
private val uiMessages = LinkedList<AiMessage>()
var uiState by mutableStateOf(UiState())
private set

Expand Down Expand Up @@ -136,37 +134,32 @@ class AssistantViewModel(
attachments = event.message.attachments,
attachmentsText = getAttachmentText(event.message.attachments)
)
messages.add(message)
uiMessages.addFirst(message)
_messages.add(0, message)
attachments.clear()

uiState = uiState.copy(
messages = uiMessages,
loading = true,
error = null
)
val result = sendAiMessage(
messages,
_messages.reversed(),
aiKey,
aiModel,
aiProvider.value,
openaiURL
)
when (result) {
is NetworkResult.Success -> {
messages.add(result.data)
uiMessages.addFirst(result.data)
_messages.add(0, result.data)

uiState = uiState.copy(messages = uiMessages, loading = false)
uiState = uiState.copy(loading = false)
}

is NetworkResult.Failure -> {
messages.removeLast()
delay(300)
uiMessages.removeFirst()
_messages.removeAt(0)

uiState = uiState.copy(
messages = uiMessages,
loading = false,
error = result
)
Expand Down Expand Up @@ -254,7 +247,6 @@ class AssistantViewModel(


data class UiState(
val messages: List<AiMessage> = emptyList(),
val loading: Boolean = false,
val error: NetworkResult.Failure? = null,
val noteView: ItemView = ItemView.LIST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
Expand Down Expand Up @@ -104,7 +105,7 @@ fun AiResultSheet(

val surfaceVariant = MaterialTheme.colorScheme.surfaceVariant
Box(
Modifier.offset {
Modifier.wrapContentHeight().offset {
if (loading) {
IntOffset(0, offset)
} else IntOffset.Zero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.animation.core.animateValue
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -17,9 +16,14 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand All @@ -32,12 +36,12 @@ fun GlowingBorder(
cornerRadius: Dp = 24.dp,
innerPadding: PaddingValues = PaddingValues(0.dp),
blur: Dp = 14.dp,
animationDuration: Int = 800
animationDuration: Int = 800,
) {
val infiniteTransition = rememberInfiniteTransition("glow")
val borderWidth by infiniteTransition.animateValue(
initialValue = 5.dp,
targetValue = 12.dp,
initialValue = 7.dp,
targetValue = 14.dp,
typeConverter = Dp.VectorConverter,
animationSpec = infiniteRepeatable(
animation = tween(
Expand All @@ -48,26 +52,24 @@ fun GlowingBorder(
),
label = "glowBorder"
)
val cornerRadiusPx = with(LocalDensity.current) { cornerRadius.toPx() }
val gradientBorder = remember { gradientBrushColor() }
val rectCornerRadius = remember { CornerRadius(cornerRadiusPx, cornerRadiusPx) }

Box(modifier) {
Box(
modifier = Modifier
.matchParentSize()
.blur(blur)
) {
Box(
modifier = Modifier
.padding(innerPadding)
.matchParentSize()
.clip(RoundedCornerShape(cornerRadius))
.border(
width = borderWidth,
brush = gradientBrushColor(),
shape = RoundedCornerShape(cornerRadius)
)
)
}
}
Box(
modifier = modifier
.blur(blur)
.padding(innerPadding)
.clip(RoundedCornerShape(cornerRadius))
.drawBehind {
drawRoundRect(
brush = gradientBorder,
size = size,
cornerRadius = rectCornerRadius,
style = Stroke(width = borderWidth.toPx())
)
}
)
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = "com.mhss.app.mybrain"
minSdk = 26
targetSdk = 35
versionCode = 10
versionName = "2.0.1"
versionCode = 11
versionName = "2.0.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -34,7 +34,7 @@ android {
debug {
isMinifyEnabled = false
applicationIdSuffix = ".debug"
isDebuggable = false
isDebuggable = true
resValue("string", "app_name", "MyBrain Debug")
}
}
Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}
-keep class com.mhss.app.widget.** { *; }
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

-dontwarn org.bouncycastle.jsse.BCSSLParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import com.mhss.app.domain.model.Task

sealed class DashboardEvent {
data class ReadPermissionChanged(val hasPermission: Boolean) : DashboardEvent()
data class UpdateTask(val task: Task) : DashboardEvent()
data class CompleteTask(val task: Task, val isCompleted: Boolean) : DashboardEvent()
data object InitAll : DashboardEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ fun DashboardScreen(
.fillMaxWidth()
.aspectRatio(1.5f),
tasks = viewModel.uiState.dashBoardTasks,
onCheck = {
viewModel.onDashboardEvent(DashboardEvent.UpdateTask(it))
onCheck = { task, completed ->
viewModel.onDashboardEvent(DashboardEvent.CompleteTask(task, completed))
},
onTaskClick = {
navController.navigate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.mhss.app.domain.model.Task
import com.mhss.app.domain.use_case.GetAllEntriesUseCase
import com.mhss.app.domain.use_case.GetAllEventsUseCase
import com.mhss.app.domain.use_case.GetAllTasksUseCase
import com.mhss.app.domain.use_case.UpdateTaskUseCase
import com.mhss.app.domain.model.DiaryEntry
import com.mhss.app.domain.use_case.UpdateTaskCompletedUseCase
import com.mhss.app.preferences.domain.model.*
import com.mhss.app.preferences.domain.use_case.GetPreferenceUseCase
import com.mhss.app.preferences.domain.use_case.SavePreferenceUseCase
Expand All @@ -34,7 +34,7 @@ class MainViewModel(
private val savePreference: SavePreferenceUseCase,
private val getAllTasks: GetAllTasksUseCase,
private val getAllEntriesUseCase: GetAllEntriesUseCase,
private val updateTask: UpdateTaskUseCase,
private val completeTask: UpdateTaskCompletedUseCase,
private val getAllEventsUseCase: GetAllEventsUseCase
) : ViewModel() {

Expand All @@ -56,8 +56,8 @@ class MainViewModel(
if (event.hasPermission)
getCalendarEvents()
}
is DashboardEvent.UpdateTask -> viewModelScope.launch {
updateTask(event.task, event.task)
is DashboardEvent.CompleteTask -> viewModelScope.launch {
completeTask(event.task.id, event.isCompleted)
}
DashboardEvent.InitAll -> collectDashboardData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fun SpacesScreen(
) { paddingValues ->
val surfaceVariant = MaterialTheme.colorScheme.surfaceVariant
LazyVerticalGrid(
columns = GridCells.Adaptive(150.dp),
columns = GridCells.Adaptive(140.dp),
modifier = Modifier.padding(paddingValues),
contentPadding = PaddingValues(
top = 10.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class BookmarkRepositoryImpl(
}
}

override suspend fun addBookmark(bookmark: Bookmark) {
withContext(ioDispatcher) {
override suspend fun addBookmark(bookmark: Bookmark): Long {
return withContext(ioDispatcher) {
bookmarkDao.insertBookmark(bookmark.toBookmarkEntity())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface BookmarkRepository {

suspend fun searchBookmarks(query: String): List<Bookmark>

suspend fun addBookmark(bookmark: Bookmark)
suspend fun addBookmark(bookmark: Bookmark): Long

suspend fun deleteBookmark(bookmark: Bookmark)

Expand Down
Loading

0 comments on commit b99aa67

Please sign in to comment.