86 lines
3.4 KiB
Kotlin
86 lines
3.4 KiB
Kotlin
package ui
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.material.Button
|
|
import androidx.compose.material.ButtonDefaults
|
|
import androidx.compose.material.Card
|
|
import androidx.compose.material.Divider
|
|
import androidx.compose.material.MaterialTheme
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.*
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import kotlinx.coroutines.launch
|
|
import model.RealTimeTrade
|
|
import network.AiService
|
|
|
|
@Composable
|
|
fun AiAnalysisView(stockName: String, currentPrice: String, trades: List<RealTimeTrade>) {
|
|
var aiOpinion by remember { mutableStateOf("분석 대기 중...") }
|
|
var isLoading by remember { mutableStateOf(false) }
|
|
val scope = rememberCoroutineScope()
|
|
|
|
// 1. 모델 경로 유효성 체크
|
|
val isModelConfigured = remember {
|
|
val path = util.AppConfigManager.modelPath
|
|
path.isNotEmpty() && java.io.File(path).exists()
|
|
}
|
|
|
|
Card(
|
|
elevation = 2.dp,
|
|
modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
|
|
backgroundColor = if (isModelConfigured) Color(0xFFF1F3F4) else Color(0xFFFFEBEE)
|
|
) {
|
|
Column(modifier = Modifier.padding(12.dp)) {
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
Text(
|
|
text = if (isModelConfigured) "🤖 AI 투자 전략" else "⚠️ AI 설정 필요",
|
|
fontWeight = FontWeight.Bold,
|
|
color = if (isModelConfigured) Color(0xFF1A73E8) else Color.Red
|
|
)
|
|
Spacer(Modifier.weight(1f))
|
|
|
|
// 2. 경로가 정상일 때만 버튼 활성화
|
|
Button(
|
|
onClick = {
|
|
scope.launch {
|
|
isLoading = true
|
|
aiOpinion = "Gemma가 데이터를 읽고 있습니다..."
|
|
aiOpinion = network.AiService.fetchAnalysis(stockName, currentPrice, trades)
|
|
isLoading = false
|
|
}
|
|
},
|
|
enabled = isModelConfigured && !isLoading, // 유효성 체크 반영
|
|
colors = ButtonDefaults.buttonColors(
|
|
backgroundColor = Color.White,
|
|
disabledBackgroundColor = Color(0xFFE0E0E0)
|
|
)
|
|
) {
|
|
Text(if (isLoading) "분석 중" else "분석 실행", fontSize = 11.sp)
|
|
}
|
|
}
|
|
|
|
if (!isModelConfigured) {
|
|
Text(
|
|
"설정에서 .gguf 모델 파일을 먼저 등록해주세요.",
|
|
color = Color.Red,
|
|
fontSize = 11.sp,
|
|
modifier = Modifier.padding(top = 4.dp)
|
|
)
|
|
} else {
|
|
Divider(Modifier.padding(vertical = 8.dp))
|
|
Text(text = aiOpinion, style = MaterialTheme.typography.body2)
|
|
}
|
|
}
|
|
}
|
|
} |