Compare commits

..

No commits in common. "bb173453c898904361f3a1bf6489061fc26021f8" and "9e7c273ec71ca2ae8dca8df6e8ddff923795912b" have entirely different histories.

2 changed files with 39 additions and 101 deletions

View File

@ -179,7 +179,7 @@ fun DrawerMenu(
verticalAlignment = Alignment.CenterVertically
) {
Text(
"Version 1.1.0",
"Version 1.0.0",
style = MaterialTheme.typography.bodySmall,
color = AppColors.OnSurfaceTertiary,
fontSize = 12.sp
@ -202,7 +202,7 @@ fun DrawerMenu(
modifier = Modifier.size(12.dp)
)
Text(
"Gemini AI",
"AI",
color = AppColors.Primary,
fontSize = 11.sp,
fontWeight = FontWeight.Bold

View File

@ -3,8 +3,6 @@ package com.example.notesai.presentation.screens.ai
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
@ -24,7 +22,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import com.example.notesai.config.APIKey
import com.example.notesai.data.local.DataStoreManager
import com.example.notesai.data.model.*
@ -142,10 +139,7 @@ fun AIHelperScreen(
isGeneratingSummary = false
}
Box(
modifier = Modifier.fillMaxSize()
) {
// MAIN CONTENT - Layer 1 (paling bawah)
Box(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier
.fillMaxSize()
@ -355,8 +349,7 @@ fun AIHelperScreen(
scrollState.animateScrollTo(scrollState.maxValue)
// Generate summary dengan Gemini
val response =
generativeModel.generateContent(summaryPrompt)
val response = generativeModel.generateContent(summaryPrompt)
val summary = response.text ?: "Gagal membuat ringkasan"
// Add AI response
@ -469,7 +462,7 @@ fun AIHelperScreen(
}
}
// Input Area - Layer 2 (di atas chat, tapi di bawah drawer)
// Input Area
Surface(
color = AppColors.Surface,
shadowElevation = 8.dp,
@ -516,8 +509,7 @@ fun AIHelperScreen(
delay(100)
scrollState.animateScrollTo(scrollState.maxValue)
val response =
generativeModel.generateContent(summaryPrompt)
val response = generativeModel.generateContent(summaryPrompt)
val summary = response.text ?: "Gagal membuat ringkasan"
chatMessages = chatMessages + ChatMessage(
@ -607,11 +599,9 @@ fun AIHelperScreen(
}
}
val fullPrompt =
"$notesContext\n\nPertanyaan: $userPrompt\n\nBerikan jawaban dalam bahasa Indonesia yang natural dan membantu."
val fullPrompt = "$notesContext\n\nPertanyaan: $userPrompt\n\nBerikan jawaban dalam bahasa Indonesia yang natural dan membantu."
val result = generativeModel.generateContent(fullPrompt)
val response =
result.text ?: "Tidak ada respons dari AI"
val response = result.text ?: "Tidak ada respons dari AI"
chatMessages = chatMessages + ChatMessage(
message = response,
@ -621,44 +611,18 @@ fun AIHelperScreen(
saveChatHistory()
} catch (e: Exception) {
errorMessage = when {
e.message?.contains(
"quota",
ignoreCase = true
) == true ->
e.message?.contains("quota", ignoreCase = true) == true ->
"⚠️ Kuota API habis. Silakan coba lagi nanti atau hubungi developer."
e.message?.contains(
"404",
ignoreCase = true
) == true ||
e.message?.contains(
"not found",
ignoreCase = true
) == true ->
e.message?.contains("404", ignoreCase = true) == true ||
e.message?.contains("not found", ignoreCase = true) == true ->
"⚠️ Model AI tidak ditemukan. Silakan hubungi developer."
e.message?.contains(
"401",
ignoreCase = true
) == true ||
e.message?.contains(
"API key",
ignoreCase = true
) == true ->
e.message?.contains("401", ignoreCase = true) == true ||
e.message?.contains("API key", ignoreCase = true) == true ->
"⚠️ API key tidak valid. Silakan hubungi developer."
e.message?.contains(
"timeout",
ignoreCase = true
) == true ->
e.message?.contains("timeout", ignoreCase = true) == true ->
"⚠️ Koneksi timeout. Periksa koneksi internet Anda."
e.message?.contains(
"network",
ignoreCase = true
) == true ->
e.message?.contains("network", ignoreCase = true) == true ->
"⚠️ Tidak ada koneksi internet. Silakan periksa koneksi Anda."
else ->
"⚠️ Terjadi kesalahan: ${e.message?.take(100) ?: "Unknown error"}"
}
@ -683,35 +647,11 @@ fun AIHelperScreen(
}
}
// DRAWER - Layer 3 (paling atas, di luar Column)
// Chat History Drawer
AnimatedVisibility(
visible = showHistoryDrawer,
enter = fadeIn() + slideInHorizontally(initialOffsetX = { -it }),
exit = fadeOut() + slideOutHorizontally(targetOffsetX = { -it }),
modifier = Modifier
.fillMaxSize()
.zIndex(10f) // Z-index lebih tinggi dari bottom bar
) {
// Backdrop + Drawer
Box(
modifier = Modifier
.fillMaxSize()
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) { showHistoryDrawer = false }
.background(Color.Black.copy(alpha = 0.5f))
) {
// Drawer Content
Box(
modifier = Modifier
.fillMaxHeight()
.fillMaxWidth(0.85f) // 85% dari lebar layar
.align(Alignment.CenterStart)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) { /* Prevent backdrop click */ }
enter = fadeIn() + slideInHorizontally(),
exit = fadeOut() + slideOutHorizontally()
) {
ChatHistoryDrawer(
chatHistories = chatHistories,
@ -737,6 +677,4 @@ fun AIHelperScreen(
)
}
}
}
}
}