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

View File

@ -3,8 +3,6 @@ package com.example.notesai.presentation.screens.ai
import androidx.compose.animation.* import androidx.compose.animation.*
import androidx.compose.animation.core.* import androidx.compose.animation.core.*
import androidx.compose.foundation.background 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.layout.*
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape 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.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import com.example.notesai.config.APIKey import com.example.notesai.config.APIKey
import com.example.notesai.data.local.DataStoreManager import com.example.notesai.data.local.DataStoreManager
import com.example.notesai.data.model.* import com.example.notesai.data.model.*
@ -142,10 +139,7 @@ fun AIHelperScreen(
isGeneratingSummary = false isGeneratingSummary = false
} }
Box( Box(modifier = Modifier.fillMaxSize()) {
modifier = Modifier.fillMaxSize()
) {
// MAIN CONTENT - Layer 1 (paling bawah)
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -355,8 +349,7 @@ fun AIHelperScreen(
scrollState.animateScrollTo(scrollState.maxValue) scrollState.animateScrollTo(scrollState.maxValue)
// Generate summary dengan Gemini // Generate summary dengan Gemini
val response = val response = generativeModel.generateContent(summaryPrompt)
generativeModel.generateContent(summaryPrompt)
val summary = response.text ?: "Gagal membuat ringkasan" val summary = response.text ?: "Gagal membuat ringkasan"
// Add AI response // Add AI response
@ -469,7 +462,7 @@ fun AIHelperScreen(
} }
} }
// Input Area - Layer 2 (di atas chat, tapi di bawah drawer) // Input Area
Surface( Surface(
color = AppColors.Surface, color = AppColors.Surface,
shadowElevation = 8.dp, shadowElevation = 8.dp,
@ -516,8 +509,7 @@ fun AIHelperScreen(
delay(100) delay(100)
scrollState.animateScrollTo(scrollState.maxValue) scrollState.animateScrollTo(scrollState.maxValue)
val response = val response = generativeModel.generateContent(summaryPrompt)
generativeModel.generateContent(summaryPrompt)
val summary = response.text ?: "Gagal membuat ringkasan" val summary = response.text ?: "Gagal membuat ringkasan"
chatMessages = chatMessages + ChatMessage( chatMessages = chatMessages + ChatMessage(
@ -607,11 +599,9 @@ fun AIHelperScreen(
} }
} }
val fullPrompt = val fullPrompt = "$notesContext\n\nPertanyaan: $userPrompt\n\nBerikan jawaban dalam bahasa Indonesia yang natural dan membantu."
"$notesContext\n\nPertanyaan: $userPrompt\n\nBerikan jawaban dalam bahasa Indonesia yang natural dan membantu."
val result = generativeModel.generateContent(fullPrompt) val result = generativeModel.generateContent(fullPrompt)
val response = val response = result.text ?: "Tidak ada respons dari AI"
result.text ?: "Tidak ada respons dari AI"
chatMessages = chatMessages + ChatMessage( chatMessages = chatMessages + ChatMessage(
message = response, message = response,
@ -621,44 +611,18 @@ fun AIHelperScreen(
saveChatHistory() saveChatHistory()
} catch (e: Exception) { } catch (e: Exception) {
errorMessage = when { errorMessage = when {
e.message?.contains( e.message?.contains("quota", ignoreCase = true) == true ->
"quota",
ignoreCase = true
) == true ->
"⚠️ Kuota API habis. Silakan coba lagi nanti atau hubungi developer." "⚠️ Kuota API habis. Silakan coba lagi nanti atau hubungi developer."
e.message?.contains("404", ignoreCase = true) == true ||
e.message?.contains( e.message?.contains("not found", ignoreCase = true) == true ->
"404",
ignoreCase = true
) == true ||
e.message?.contains(
"not found",
ignoreCase = true
) == true ->
"⚠️ Model AI tidak ditemukan. Silakan hubungi developer." "⚠️ Model AI tidak ditemukan. Silakan hubungi developer."
e.message?.contains("401", ignoreCase = true) == true ||
e.message?.contains( e.message?.contains("API key", ignoreCase = true) == true ->
"401",
ignoreCase = true
) == true ||
e.message?.contains(
"API key",
ignoreCase = true
) == true ->
"⚠️ API key tidak valid. Silakan hubungi developer." "⚠️ 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." "⚠️ 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." "⚠️ Tidak ada koneksi internet. Silakan periksa koneksi Anda."
else -> else ->
"⚠️ Terjadi kesalahan: ${e.message?.take(100) ?: "Unknown error"}" "⚠️ 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( AnimatedVisibility(
visible = showHistoryDrawer, visible = showHistoryDrawer,
enter = fadeIn() + slideInHorizontally(initialOffsetX = { -it }), enter = fadeIn() + slideInHorizontally(),
exit = fadeOut() + slideOutHorizontally(targetOffsetX = { -it }), exit = fadeOut() + slideOutHorizontally()
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 */ }
) { ) {
ChatHistoryDrawer( ChatHistoryDrawer(
chatHistories = chatHistories, chatHistories = chatHistories,
@ -738,5 +678,3 @@ fun AIHelperScreen(
} }
} }
} }
}
}