Compare commits

..

No commits in common. "master" and "3693612b209eef084209a222aaacb4ce1970ef71" have entirely different histories.

75 changed files with 2692 additions and 11726 deletions

View File

@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidTestResultsUserPreferences">
<option name="androidTestResultsTableState">
<map>
<entry key="-242615617">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Medium_Phone_API_36.1" value="120" />
<entry key="Tests" value="360" />
<entry key="samsung SM-A127F" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="291230364">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Tests" value="360" />
<entry key="samsung SM-A127F" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="362346923">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Tests" value="360" />
<entry key="samsung SM-A127F" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="459819240">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Tests" value="360" />
<entry key="samsung SM-A127F" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="664695232">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Tests" value="360" />
<entry key="samsung SM-A127F" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
</map>
</option>
</component>
</project>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AppInsightsSettings">
<option name="tabSettings">
<map>
<entry key="Firebase Crashlytics">
<value>
<InsightsFilterSettings>
<option name="signal" value="SIGNAL_UNSPECIFIED" />
<option name="timeIntervalDays" value="THIRTY_DAYS" />
<option name="visibilityType" value="ALL" />
</InsightsFilterSettings>
</value>
</entry>
</map>
</option>
</component>
</project>

View File

@ -4,30 +4,15 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-12-18T06:53:17.556062600Z">
<DropdownSelection timestamp="2025-12-10T12:35:04.538299500Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Fazri Abdurrahman\.android\avd\Medium_Phone.avd" />
<DeviceId pluginId="PhysicalDevice" identifier="serial=10DEC90GZE0004R" />
</handle>
</Target>
</DropdownSelection>
<DialogSelection />
</SelectionState>
<SelectionState runConfigName="DataStoreManagerTest">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
<SelectionState runConfigName="TrashFunctionalityTest">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
<SelectionState runConfigName="SearchFunctionalityTest">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
<SelectionState runConfigName="AIChatFunctionalityTest">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
<SelectionState runConfigName="FileUploadFunctionalityTest">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
</selectionStates>
</component>
</project>

8
.idea/markdown.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettings">
<option name="previewPanelProviderInfo">
<ProviderInfo name="Compose (experimental)" className="com.intellij.markdown.compose.preview.ComposePanelProvider" />
</option>
</component>
</project>

6
.idea/studiobot.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="StudioBotProjectSettings">
<option name="shareContext" value="OptedIn" />
</component>
</project>

View File

@ -1,76 +0,0 @@
kotlin version: 2.0.21
error message: org.jetbrains.kotlin.util.FileAnalysisException: While analysing C:/Users/Fazri Abdurrahman/AndroidStudioProjects/NotesAI/app/src/main/java/com/example/notesai/MainActivity.kt:40:5: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:57)
at org.jetbrains.kotlin.fir.FirCliExceptionHandler.handleExceptionOnFileAnalysis(Utils.kt:249)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:46)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.resolveAndCheckFir(firUtils.kt:77)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.buildResolveAndCheckFirViaLightTree(firUtils.kt:88)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModuleToAnalyzedFir(jvmCompilerPipeline.kt:319)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModulesUsingFrontendIrAndLightTree(jvmCompilerPipeline.kt:118)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:148)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:43)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:103)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:49)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:464)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:73)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:506)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:423)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:301)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:129)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:675)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1660)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.requireNotNull(KtDiagnosticReportHelpers.kt:68)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn(KtDiagnosticReportHelpers.kt:39)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn$default(KtDiagnosticReportHelpers.kt:31)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkSourceElement(FirIncompatibleClassExpressionChecker.kt:50)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkType$checkers(FirIncompatibleClassExpressionChecker.kt:42)
at org.jetbrains.kotlin.fir.analysis.checkers.type.FirIncompatibleClassTypeChecker.check(FirIncompatibleClassTypeChecker.kt:17)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.check(TypeCheckersDiagnosticComponent.kt:81)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:53)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:19)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.analysis.collectors.CheckerRunningDiagnosticCollectorVisitor.checkElement(CheckerRunningDiagnosticCollectorVisitor.kt:24)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:248)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl.acceptChildren(FirSimpleFunctionImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:118)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirSimpleFunction.accept(FirSimpleFunction.kt:51)
at org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl.acceptChildren(FirRegularClassImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitClassAndChildren(AbstractDiagnosticCollectorVisitor.kt:87)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:92)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirRegularClass.accept(FirRegularClass.kt:48)
at org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl.acceptChildren(FirFileImpl.kt:57)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:1151)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirFile.accept(FirFile.kt:42)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector.collectDiagnostics(AbstractDiagnosticCollector.kt:36)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:34)
... 33 more

View File

@ -1,76 +0,0 @@
kotlin version: 2.0.21
error message: org.jetbrains.kotlin.util.FileAnalysisException: While analysing C:/Users/Fazri Abdurrahman/AndroidStudioProjects/NotesAI/app/src/main/java/com/example/notesai/MainActivity.kt:40:5: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:57)
at org.jetbrains.kotlin.fir.FirCliExceptionHandler.handleExceptionOnFileAnalysis(Utils.kt:249)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:46)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.resolveAndCheckFir(firUtils.kt:77)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.buildResolveAndCheckFirViaLightTree(firUtils.kt:88)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModuleToAnalyzedFir(jvmCompilerPipeline.kt:319)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModulesUsingFrontendIrAndLightTree(jvmCompilerPipeline.kt:118)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:148)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:43)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:103)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:49)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:464)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:73)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:506)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:423)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:301)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:129)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:675)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1660)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.requireNotNull(KtDiagnosticReportHelpers.kt:68)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn(KtDiagnosticReportHelpers.kt:39)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn$default(KtDiagnosticReportHelpers.kt:31)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkSourceElement(FirIncompatibleClassExpressionChecker.kt:50)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkType$checkers(FirIncompatibleClassExpressionChecker.kt:42)
at org.jetbrains.kotlin.fir.analysis.checkers.type.FirIncompatibleClassTypeChecker.check(FirIncompatibleClassTypeChecker.kt:17)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.check(TypeCheckersDiagnosticComponent.kt:81)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:53)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:19)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.analysis.collectors.CheckerRunningDiagnosticCollectorVisitor.checkElement(CheckerRunningDiagnosticCollectorVisitor.kt:24)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:248)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl.acceptChildren(FirSimpleFunctionImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:118)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirSimpleFunction.accept(FirSimpleFunction.kt:51)
at org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl.acceptChildren(FirRegularClassImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitClassAndChildren(AbstractDiagnosticCollectorVisitor.kt:87)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:92)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirRegularClass.accept(FirRegularClass.kt:48)
at org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl.acceptChildren(FirFileImpl.kt:57)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:1151)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirFile.accept(FirFile.kt:42)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector.collectDiagnostics(AbstractDiagnosticCollector.kt:36)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:34)
... 33 more

View File

@ -1,76 +0,0 @@
kotlin version: 2.0.21
error message: org.jetbrains.kotlin.util.FileAnalysisException: While analysing C:/Users/Fazri Abdurrahman/AndroidStudioProjects/NotesAI/app/src/main/java/com/example/notesai/MainActivity.kt:40:5: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:57)
at org.jetbrains.kotlin.fir.FirCliExceptionHandler.handleExceptionOnFileAnalysis(Utils.kt:249)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:46)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.resolveAndCheckFir(firUtils.kt:77)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.buildResolveAndCheckFirViaLightTree(firUtils.kt:88)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModuleToAnalyzedFir(jvmCompilerPipeline.kt:319)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModulesUsingFrontendIrAndLightTree(jvmCompilerPipeline.kt:118)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:148)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:43)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:103)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:49)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:464)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:73)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:506)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:423)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:301)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:129)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:675)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1660)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.requireNotNull(KtDiagnosticReportHelpers.kt:68)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn(KtDiagnosticReportHelpers.kt:39)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn$default(KtDiagnosticReportHelpers.kt:31)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkSourceElement(FirIncompatibleClassExpressionChecker.kt:50)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkType$checkers(FirIncompatibleClassExpressionChecker.kt:42)
at org.jetbrains.kotlin.fir.analysis.checkers.type.FirIncompatibleClassTypeChecker.check(FirIncompatibleClassTypeChecker.kt:17)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.check(TypeCheckersDiagnosticComponent.kt:81)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:53)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:19)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.analysis.collectors.CheckerRunningDiagnosticCollectorVisitor.checkElement(CheckerRunningDiagnosticCollectorVisitor.kt:24)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:248)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl.acceptChildren(FirSimpleFunctionImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:118)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirSimpleFunction.accept(FirSimpleFunction.kt:51)
at org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl.acceptChildren(FirRegularClassImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitClassAndChildren(AbstractDiagnosticCollectorVisitor.kt:87)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:92)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirRegularClass.accept(FirRegularClass.kt:48)
at org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl.acceptChildren(FirFileImpl.kt:57)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:1151)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirFile.accept(FirFile.kt:42)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector.collectDiagnostics(AbstractDiagnosticCollector.kt:36)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:34)
... 33 more

View File

@ -1,76 +0,0 @@
kotlin version: 2.0.21
error message: org.jetbrains.kotlin.util.FileAnalysisException: While analysing C:/Users/Fazri Abdurrahman/AndroidStudioProjects/NotesAI/app/src/main/java/com/example/notesai/MainActivity.kt:40:5: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:57)
at org.jetbrains.kotlin.fir.FirCliExceptionHandler.handleExceptionOnFileAnalysis(Utils.kt:249)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:46)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.resolveAndCheckFir(firUtils.kt:77)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.buildResolveAndCheckFirViaLightTree(firUtils.kt:88)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModuleToAnalyzedFir(jvmCompilerPipeline.kt:319)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModulesUsingFrontendIrAndLightTree(jvmCompilerPipeline.kt:118)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:148)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:43)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:103)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:49)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:464)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:73)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:506)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:423)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:301)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:129)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:675)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1660)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.requireNotNull(KtDiagnosticReportHelpers.kt:68)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn(KtDiagnosticReportHelpers.kt:39)
at org.jetbrains.kotlin.diagnostics.KtDiagnosticReportHelpersKt.reportOn$default(KtDiagnosticReportHelpers.kt:31)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkSourceElement(FirIncompatibleClassExpressionChecker.kt:50)
at org.jetbrains.kotlin.fir.analysis.checkers.expression.FirIncompatibleClassExpressionChecker.checkType$checkers(FirIncompatibleClassExpressionChecker.kt:42)
at org.jetbrains.kotlin.fir.analysis.checkers.type.FirIncompatibleClassTypeChecker.check(FirIncompatibleClassTypeChecker.kt:17)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.check(TypeCheckersDiagnosticComponent.kt:81)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:53)
at org.jetbrains.kotlin.fir.analysis.collectors.components.TypeCheckersDiagnosticComponent.visitResolvedTypeRef(TypeCheckersDiagnosticComponent.kt:19)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.analysis.collectors.CheckerRunningDiagnosticCollectorVisitor.checkElement(CheckerRunningDiagnosticCollectorVisitor.kt:24)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:248)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitResolvedTypeRef(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.accept(FirResolvedTypeRef.kt:28)
at org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl.acceptChildren(FirSimpleFunctionImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:118)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitSimpleFunction(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirSimpleFunction.accept(FirSimpleFunction.kt:51)
at org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl.acceptChildren(FirRegularClassImpl.kt:63)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitWithDeclarationAndReceiver(AbstractDiagnosticCollectorVisitor.kt:311)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitClassAndChildren(AbstractDiagnosticCollectorVisitor.kt:87)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:92)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitRegularClass(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirRegularClass.accept(FirRegularClass.kt:48)
at org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl.acceptChildren(FirFileImpl.kt:57)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitNestedElements(AbstractDiagnosticCollectorVisitor.kt:38)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:1151)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorVisitor.visitFile(AbstractDiagnosticCollectorVisitor.kt:30)
at org.jetbrains.kotlin.fir.declarations.FirFile.accept(FirFile.kt:42)
at org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector.collectDiagnostics(AbstractDiagnosticCollector.kt:36)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:34)
... 33 more

View File

@ -1,361 +0,0 @@
# **AI Notes Changelog**
## **Tim Pengembang**
* Dendi Yogia Pratama
* Raihan Ariq Muzakki
* Fazri Abdurrahman
# **Version 1.0.0 Initial Release**
## **Sprint 1: Struktur Dasar Aplikasi**
### **Struktur & Navigation**
* **Setup navigation system** - Implementasi routing antar halaman (Beranda, Arsip, Sampah)
* **Menu Drawer** - Navigation drawer dengan list menu (Beranda, Berbintang, Arsip, Sampah)
* **Bottom Navigation** - Home & AI Helper tabs dengan icon navigation
* **Top App Bar** - Menu hamburger dan search icon dengan Material3 styling
* **Screen Architecture** - Pembuatan screen Arsip, Sampah, Berbintang, AI Helper
### **Theme & Styling**
* **Material3 Dark Theme** - Setup color scheme dengan dark mode default
* **Color System** - Primary/Secondary colors dengan gradient presets (8 kombinasi warna)
* **Consistent Design** - Rounded corners (12dp, 16dp, 20dp), shadow, elevation
* **Smooth Animations** - Drawer slide, FAB scale, card transitions dengan spring animations
* **Typography System** - Optimasi font sizes dan line heights untuk readability
### **Category Management**
* **Category Model** - Data class dengan gradient colors dan timestamp
* **Category Dialog** - Form tambah/edit kategori dengan nama + gradient picker
* **Category Card** - Design dengan icon folder, nama, jumlah catatan, gradient background
* **Staggered Grid Layout** - 2 kolom responsive dengan LazyVerticalStaggeredGrid
* **Category Actions** - Menu dropdown (⋮) untuk edit dan delete kategori
* **Empty State** - Pesan "Buat kategori pertama Anda" dengan icon
### **Note Management**
* **Note Model** - Data class dengan title, content, timestamp, isPinned, isArchived
* **Note Dialog** - Form dengan judul, deskripsi, simpan, batal, hapus
* **Note Card** - Preview dengan judul, deskripsi, timestamp, pin icon
* **Full-screen Editor** - Editable note view dengan auto-save dan actions
* **Pin Feature** - Toggle pin/unpin untuk catatan penting dengan sorting priority
* **Archive & Delete** - Actions untuk arsip dan soft delete notes
* **Search Functionality** - Real-time search berdasarkan judul dan isi (case-insensitive)
* **Smart Sorting** - Berdasarkan pin status dan timestamp (descending)
### **AI Assistant**
* **Gemini AI Integration** - Setup Google Generative AI SDK dengan gemini-2.5-flash
* **AI Helper Screen** - Layout chat interface dengan header dan statistics
* **Category Context Selector** - Dropdown untuk filter konteks AI berdasarkan kategori
* **Statistics Display** - Total catatan, pinned notes, jumlah kategori
* **Chat Interface** - User & AI bubble dengan different styling dan timestamp
* **Prompt Engineering** - Context builder dengan data catatan user (max 10 terbaru)
* **Suggestion Chips** - Quick question templates untuk user guidance
* **Copy to Clipboard** - Copy jawaban AI dengan confirmation feedback
* **Loading & Error States** - Circular progress indicator dan error messages
* **API Configuration** - Temperature 0.8, topK 40, topP 0.95, maxOutputTokens 4096
* **Auto-scroll Chat** - Scroll ke bottom otomatis dengan LaunchedEffect
### **Data Persistence**
* **DataStore Implementation** - Preferences DataStore untuk local storage
* **DataStoreManager Class** - Centralized dengan categoriesFlow & notesFlow
* **Auto-save dengan Debounce** - 500ms delay untuk optimize I/O operations
* **Flow-based Loading** - Reactive data loading dengan Flow collection
* **Error Handling** - Try-catch untuk semua I/O operations
* **Serializable Models** - JSON serialization dengan extension functions
### **UI/UX Enhancements**
* **Visual Feedback** - Click ripples, copy confirmation, loading states
* **Empty States** - Icon + descriptive messages untuk setiap screen
* **Confirmation Dialogs** - AlertDialog untuk arsip, hapus, delete actions
* **Search Empty State** - "Tidak ada hasil" message saat search kosong
* **Custom TextField** - Styled text input dengan consistent design
* **Date Formatter Utility** - Format timestamp ke readable Indonesian format
---
## **Sprint 2: Project Restructuring & Advanced Features**
### **Project Architecture**
* **Clean Architecture Migration** - Dari 3 file monolith ke modular structure
* **Data Layer Separation** - Models ke `data/model/` (Category, Note, ChatMessage)
* **Local Storage Layer** - DataStoreManager ke `data/local/` dengan PreferencesKeys
* **Component Extraction** - Screen components ke folder terpisah (main, starred, archive, trash)
* **Utilities Creation** - Constants.kt, DateFormatter.kt, Extensions.kt untuk reusability
* **Import Optimization** - Update semua import sesuai package structure baru
### **Search & Filter**
* **Beranda Search** - Real-time search kategori berdasarkan nama
* **Category Notes Search** - Search catatan di dalam kategori (judul & isi)
* **Search Filtering** - Live filtering saat user mengetik
* **Search Empty State** - Descriptive message dengan alternative suggestions
### **Category Features**
* **Edit Category** - Dialog untuk ubah nama dan gradient dengan pre-filled form
* **Delete Category** - Menu dropdown dengan confirmation dialog
* **Category Actions Menu** - Icon ⋮ untuk access edit & delete options
* **Gradient Preview** - Visual preview saat edit kategori
### **Trash System**
* **Soft Delete Implementation** - isDeleted flag untuk Category dan Note
* **Trash Screen** - Tampilkan kategori & notes yang terhapus
* **TrashCategoryCard Component** - Card khusus dengan restore & delete permanent actions
* **Restore Feature** - Pulihkan kategori beserta semua notes di dalamnya
* **Permanent Delete** - Hapus kategori dan notes secara irreversible dengan confirmation
* **Counter Display** - Jumlah items terhapus di trash
* **Global Filter** - Filter `!isDeleted` di semua screen untuk hide deleted items
### **Bug Fixes & Optimization**
* **Runtime Error Debugging** - Fix NotImplementedError & FATAL EXCEPTION issues
* **Google Play Services Handling** - Error handling untuk GMS dependencies
* **Component Migration** - Update deprecated Divider ke HorizontalDivider
* **Gradle Optimization** - Cleanup unnecessary dependencies
* **State Management** - Proper state hoisting dan recomposition optimization
### **Documentation**
* **Migration Guide** - Step-by-step panduan untuk project restructuring
* **Debugging Guide** - Troubleshooting common issues dan error handling
---
# **Version 1.1.0 AI Helper Screen Enhancement & UI Refinement**
## **Sprint 3: AI Helper Screen Features & Modern UI Redesign**
### **AI Assistant Enhancements**
* **History Chat AI dengan Drawer Menu** - Riwayat percakapan AI tersimpan permanen, dikelompokkan per kategori
* **Chat History Management** - Load previous chat, delete history, start new chat dengan auto-save
* **Markdown Parser untuk AI Response** - Support bold, italic, code blocks, headers, lists, quotes, links
* **Improved Error Handling** - User-friendly error messages untuk quota, network, API issues
* **Gemini Model Update** - Switch ke gemini-1.5-flash untuk stabilitas optimal
### **Theme System**
* **Dark/Light Theme Toggle** - Dual theme dengan persistent storage di drawer menu
* **Reactive Color System** - Dynamic color switching untuk semua components
* **Complete Color Palette** - DarkColors dan LightColors objects untuk consistency
### **UI/UX Modernization**
* **Floating Design System** - TopBar dan BottomBar dengan floating style, rounded corners, shadow
* **Consistent Component Style** - Unified design language dengan CircleShape buttons
* **Optimized Layouts** - Better spacing dan vertical action stack untuk maximize content space
### **Data & Navigation**
* **Note Edit & Delete from Card** - Menu dropdown pada NoteCard untuk quick actions
* **Race Condition Fix** - Guard flags dan lifecycle-aware auto-save untuk data persistence
* **Simplified Navigation** - Unified drawer menu, remove redundant back buttons
* **Extended DataStore** - Support chat history, theme preference, improved error handling
---
## **Sprint 4: Rich Text Editor Core Features & AI Chat History UI/UX Improvements**
### **Rich Text Editing**
* **Hybrid Rich Text Editor (WYSIWYG)** Edit teks dengan format langsung tanpa syntax markdown terlihat
* **Bold, Italic, Underline** Formatting bersifat toggle dan tetap aktif sampai dimatikan
* **Heading & Bullet List** Support heading (H1H3) dan bullet list tanpa konflik antar format
* **Undo / Redo** Riwayat perubahan editor terintegrasi
### **Floating Toolbar**
* **Draggable Mini Toolbar** Toolbar dapat dipindahkan bebas oleh user
* **Active State Indicator** Icon toolbar menandakan format aktif (Bold, Italic, dll)
* **Minimal UI** Toolbar kecil agar tidak mengganggu area pengetikan
* **Keyboard-Aware Positioning** Posisi toolbar menyesuaikan saat keyboard muncul
### **Cursor & Editing Stability**
* **Stable Cursor & Selection** Insertion point dan selection handle akurat saat mengetik
* **IME & Keyboard Safe** Editor tetap stabil saat keyboard resize / rotate
* **Auto Bring-Into-View** Cursor selalu terlihat saat mengetik di area bawah layar
### **Data Persistence**
* **Format Tersimpan Permanen** Rich text tidak hilang setelah save atau reopen
* **Auto Save Lifecycle-Aware** Catatan otomatis tersimpan saat app background / keluar
* **Markdown Compatibility** Support import & export markdown secara aman
### **Chat History Enhancements**
* **Compact Modern Design** - Item lebih kecil dengan horizontal layout dan 30 karakter limit
* **Search & Filter System** - Real-time search dengan category dropdown filtering
* **Date Grouping** - Auto-group: "Hari Ini", "Kemarin", "Minggu Ini", "Lebih Lama"
* **Edit Title with Markdown** - Custom title support: **bold**, *italic*, `code`, ~~strike~~
* **Context Menu** - Three-dot menu (⋮) untuk Edit dan Delete actions
* **Live Preview** - Real-time markdown preview saat edit title
### **Technical Updates**
* **ChatHistory Model** - Added `customTitle: String?` field
* **DataStore Integration** - New `updateChatHistoryTitle()` function
* **Smart Truncation** - Auto-truncate preview ke 30 char dengan `toSafeChatPreview()`
* **Markdown Parser** - Inline markdown rendering untuk titles dengan proper styling
* **Character Counter** - Visual feedback dengan color indicator (Gray → Primary → Red)
### **User Experience**
* **Better Empty States** - Informative UI untuk empty search dan no history
* **Smooth Animations** - Slide transitions untuk dialogs
* **Input Validation** - Max 30 char dengan real-time blocking
* **Focus Management** - Seamless editing experience dengan auto-focus
> Rich Text Editor butuh dikembangkan lagi lebih advance
---
## **Sprint 5: AI Assistant Enhancements & Smart Organization Features**
### **Copy Plain Text Feature**
* **Dual Copy Options** Dropdown menu dengan 2 pilihan: "Copy dengan Format" dan "Copy Teks Asli"
* **Smart Markdown Stripper** Utility untuk remove bold, italic, code, headers, lists, links dari text
* **Visual Feedback** Animated checkmark indicator dengan auto-hide setelah 2 detik
* **Format Preservation** Copy dengan format maintain semua markdown syntax
* **Clean Output** Plain text copy menghasilkan text bersih tanpa formatting apapun
### **Document Upload & AI Summary**
* **Multi-Format Support** Upload PDF, TXT, dan DOCX files dengan file picker
* **Smart PDF Parser** PDFBox Android integration untuk extract text dari PDF documents
* **Lightweight DOCX Parser** Custom XML-based parser tanpa Apache POI dependency
* **Auto-Summary Generation** AI auto-generate ringkasan maksimal 300 kata saat file di-upload
* **File Validation** Maximum 10MB dengan clear error messaging untuk setiap kasus
* **Loading Integration** Loading indicator "Membuat ringkasan..." terintegrasi di chat area
* **Chat Format** Upload result format: "📄 Upload file: filename" dengan summary response
### **Category Pin System**
* **Pin/Unpin Toggle** Quick access untuk kategori favorit dengan dropdown menu
* **Visual Pin Indicator** 📌 icon dengan scale dan fade animations
* **Smart Sorting Logic** Priority sorting: pinned categories (DESC) → timestamp (DESC)
* **Persistent Storage** Pin status tersimpan di DataStore dengan backward compatibility
* **Multiple Pins Support** User dapat pin multiple categories dengan proper grouping
* **Context Menu Integration** Pin option di dropdown: "Pin Kategori" / "Lepas Pin"
### **Technical Implementation**
* **MarkdownStripper.kt** Utility class dengan regex-based markdown removal
* **FileParser.kt** Centralized file parsing untuk PDF, TXT, DOCX
* **Category Model Update** Added `isPinned: Boolean` field dengan serialization support
* **FileParseResult** Sealed class untuk type-safe file parsing results
* **PDFBoxResourceLoader** Proper initialization dalam Application.onCreate()
* **State Management** Combined loading states untuk chat dan file upload
### **User Experience**
* **Smooth Transitions** Loading states dengan color differentiation (Primary vs Secondary)
* **Error Handling** Comprehensive error messages untuk berbagai failure scenarios
* **Auto-Scroll** Scroll to bottom saat upload file untuk show loading indicator
* **Disabled States** Upload button hidden saat processing untuk prevent duplicate actions
* **Persistence** Pin status dan file summary survive app restart
# **Sprint 6: Functional Testing & Documentation**
## **Testing Implementation**
### **Test Methodology Design**
* **Black-Box Functional Testing** Pengujian dari perspektif end-user dengan verifikasi Expected vs Actual Result
* **Automated Unit Testing** 59 automated tests untuk validasi business logic internal
* **Test Case Design** 6 comprehensive test cases (TC-01 hingga TC-06)
* **Evidence Collection** Screenshot documentation untuk setiap test case
* **Test Report Generation** Structured test summary dengan metrics dan status
### **Test Infrastructure Setup**
* **JUnit 4 Framework** Core testing framework untuk Android unit tests
* **AndroidX Test Library** Android-specific testing utilities dan test runners
* **Kotlin Coroutines Test** Testing library untuk asynchronous code dengan runBlocking
* **Test Isolation** Unique DataStore instances per test untuk prevent data contamination
* **Test Execution** Configure test runner dan gradle tasks untuk automated testing
### **Unit Test Development**
* **DataStoreManagerTest** 8 tests untuk CRUD operations, autosave, dan pin functionality
* **TrashFunctionalityTest** 11 tests untuk soft delete, restore, dan permanent delete
* **SearchFunctionalityTest** 14 tests untuk realtime search dengan berbagai scenarios
* **AIChatFunctionalityTest** 14 tests untuk context building dan chat history management
* **FileUploadFunctionalityTest** 12 tests untuk file parsing dan summary generation
### **Test Coverage Achievement**
* **Total Test Cases** 6 functional test cases dengan screenshot evidence
* **Total Unit Tests** 59 automated tests covering critical business logic
* **Success Rate** 100% pass rate untuk semua tests
* **Execution Time** Average ~2 minutes untuk full test suite
* **Code Coverage** 100% coverage untuk tested components (DataStore, Models, Utilities)
### **Bug Fixes & Test Iterations**
* **Test Isolation Issues** Fixed data contamination dengan unique DataStore per test
* **Async Testing** Resolved suspend function testing dengan proper runBlocking usage
* **Chat History Tests** Fixed unique ID collision dengan improved test data management
* **Error Handling** Added comprehensive error handling untuk file I/O operations
* **Test Stability** Achieved consistent test results dengan proper setup/teardown
---
## **Documentation Development**
### **Technical Documentation**
* **Testing Methodology** 16-section comprehensive document explaining black-box testing approach
* **Architecture Documentation** Package structure, data flow, dan component relationships
* **API Documentation** Gemini API integration, endpoints, dan configuration details
* **Code Comments** Inline documentation untuk complex logic dan business rules
* **Setup Guide** Step-by-step installation dan configuration instructions
### **User Documentation**
* **User Guide** Complete panduan penggunaan dengan 7 user flows dan screenshots
* **Feature Documentation** Detailed explanation untuk setiap fitur utama aplikasi
* **Quick Start Guide** 6-step quick reference untuk new users
* **Troubleshooting Guide** Common issues dan solutions untuk end-users
* **FAQ Section** Frequently asked questions dengan clear answers
### **Project Documentation**
* **README.md** Comprehensive project overview dengan badges, links, dan quick navigation
* **CHANGELOG.md** Detailed version history dengan sprint breakdown dan feature tracking
* **TEST_SUMMARY_REPORT.md** Complete test report dengan metrics, results, dan evidence
* **DEVELOPMENT_PLAN.md** Sprint history, roadmap, dan future development planning
* **Academic Report** 35-page formal documentation untuk course submission
### **Visual Documentation**
* **Wireframe Design** Complete app wireframe dengan all screens dan navigation flows
* **Screenshot Collection** 35+ screenshots documenting every feature dan user flow
* **Mockup Integration** High-fidelity mockups embedded dalam user guide
* **Architecture Diagrams** Visual representation of data layer, presentation layer, dan flow
* **Test Evidence** Screenshot proof untuk setiap test case execution
### **Reference Documentation**
* **Dependencies List** Complete list of libraries dengan version numbers
* **Tech Stack Documentation** Detailed explanation of technology choices
* **API References** Links to official documentation untuk Gemini, Android, Kotlin
* **Academic Citations** Proper citation format untuk research sources (33 references)
* **Version Control** Git workflow documentation dan branching strategy
---
## 🎯 Fitur Utama (Core Features)
1. **Note Management System** ⭐ (PRIMARY)
* Create, Read, Update, Delete catatan
* Organize notes dalam categories
* Pin notes untuk quick access
* Archive & Trash system dengan soft delete
* Full-screen rich text editor dengan WYSIWYG
* Real-time search & filter notes
2. **AI Assistant** 🤖 (PRIMARY)
* Chat dengan AI menggunakan Gemini 2.5 Flash
* Context-aware responses berdasarkan notes user
* Chat history management dengan persistent storage
* Document upload & auto-summary (PDF, TXT, DOCX)
* Markdown support untuk AI responses
* Copy plain text atau formatted text
3. **Category Organization** 📁 (CORE)
* Create & manage categories dengan 8 gradient color presets
* Pin favorite categories untuk quick access
* Smart sorting: pinned categories → timestamp descending
* Category-based note filtering dengan statistics
* Staggered grid layout responsive
4. **Rich Text Editor** ✏️ (CORE)
* WYSIWYG (What You See Is What You Get) editing experience tanpa raw markdown
* Bold, italic, underline, headings (H1-H3), bullet lists
* Floating draggable toolbar dengan active state indicators
* Undo/Redo functionality
* Markdown compatibility untuk import/export
* Auto-save lifecycle-aware
5. **Data Persistence** 💾 (ESSENTIAL)
* Local storage dengan DataStore Preferences
* Auto-save dengan debounce (500ms delay)
* Theme preference storage (dark/light mode)
* Chat history persistence dengan serialization
* Flow-based reactive data loading
* Error handling untuk semua I/O operations

Binary file not shown.

579
README.md
View File

@ -1,579 +0,0 @@
<div align="center">
<img title="Logo NotesAI" src="docs/Logo%20Aplikasi.png" width="150" height="150">
# NotesAI - AI-Powered Note Taking App 1.1.0
![NotesAI Banner](https://img.shields.io/badge/NotesAI-v1.1.0-blue?style=for-the-badge)
![Platform](https://img.shields.io/badge/Platform-Android-green?style=for-the-badge&logo=android)
![Kotlin](https://img.shields.io/badge/Kotlin-100%25-purple?style=for-the-badge&logo=kotlin)
**Aplikasi pencatatan cerdas berbasis AI untuk Android dengan fitur organisasi terstruktur dan AI Assistant**
[📖 Dokumentasi Lengkap](./docs/Laporan%20Dokumentasi%20Aplikasi%20-%20Kelompok%201.pdf) | [🧪 Test Report](./TEST_SUMMARY_REPORT.md) | [📋 Changelog](./CHANGELOG.md)
Unduh [NotesAI.apk](./NotesAI.apk)
</div>
---
## 👥 Tim Pengembang
**Kelompok 1 - Kelas F5A5**
| Nama | NPM |
|------|-----|
| Dendi Yogia Pratama | 202310715051 |
| Raihan Ariq Muzakki | 202310715297 |
| Fazri Abdurahman | 202310715082 |
**Dosen Pengampu:** Arif Rifai Dwiyanto, ST., MTI
**Mata Kuliah:** Pemrograman Perangkat Bergerak
**Institusi:** Universitas Bhayangkara Jakarta Raya
---
## 📌 Informasi Proyek
- **Nama Aplikasi:** NotesAI
- **Repository:** [NotesAI](https://git.lab.ubharajaya.ac.id/202310715297-RAIHAN-ARIQ-MUZAKKI/NotesAI.git)
- **Platform:** Android (Minimum API 24 / Android 7.0)
- **Bahasa:** Kotlin 100%
- **UI Framework:** Jetpack Compose + Material 3
---
## 🎯 Tujuan dan Sasaran Aplikasi
### Masalah yang Dipecahkan
1. **Catatan tidak terorganisir** - Catatan bercampur tanpa struktur yang jelas
2. **Sulit mencari informasi** - Kehilangan waktu mencari catatan penting
3. **Kurang interaktif** - Tidak ada bantuan untuk merangkum atau menganalisis catatan
4. **Risiko kehilangan data** - Catatan terhapus permanen tanpa backup
### Target Pengguna
- 🎓 **Mahasiswa** (18-25 tahun) - Catatan kuliah, tugas, ringkasan dokumen
- 💼 **Profesional** (22-40 tahun) - Meeting notes, to-do lists, catatan kerja
- 👤 **Pengguna Umum** (18-40 tahun) - Catatan pribadi, jurnal, daftar belanja
### Keunggulan NotesAI
**Organisasi Terstruktur** - Sistem kategori dengan visual gradien warna
**AI Assistant** - Powered by Gemini 2.5 Flash untuk respons kontekstual
**Rich Text Editor** - WYSIWYG editor dengan drag-and-drop toolbar
**Smart Search** - Pencarian realtime dengan filter kategori
**Data Safety** - Soft delete dengan trash & restore functionality
**Document Parser** - Upload PDF/TXT/DOCX dengan auto-summary
---
## ✨ Fitur Utama
### 1⃣ Note Management System
- ✏️ **CRUD Operations** - Create, Read, Update, Delete catatan
- 📁 **Category Organization** - Pengelompokan visual dengan gradien warna
- 📌 **Pin Priority** - Pin notes/kategori untuk akses cepat
- 🗄️ **Archive & Trash** - Soft delete dengan kemampuan restore
- 🎨 **Rich Text Editor** - Bold, italic, underline, heading, bullet list
- 🔍 **Smart Search** - Realtime search dengan case-insensitive
### 2⃣ AI Assistant
- 🤖 **Contextual AI Chat** - AI memahami konteks dari catatan Anda
- 📄 **Document Upload** - Support PDF, TXT, DOCX
- 📝 **Auto Summary** - Ringkasan otomatis dari dokumen
- 💬 **Chat History** - Penyimpanan percakapan persistent
- 🎯 **Category Filter** - Filter konteks berdasarkan kategori
- ✍️ **Markdown Support** - Formatted AI responses
### 3⃣ Data Management
- 💾 **Local Storage** - DataStore Preferences untuk data persistence
- 🔄 **Autosave** - Lifecycle-aware autosave dengan debounce 500ms
- 🌙 **Theme Preference** - Dark/Light mode support
- 📊 **Reactive Data** - Flow-based reactive data loading
- ⚡ **Fast Performance** - Optimized untuk pengalaman smooth
---
## 📊 Riset dan Analisis
### Analisis Pasar
Berdasarkan riset pasar 2025:
- **70% responden** percaya AI meningkatkan produktivitas kerja *(Eurobarometer, Feb 2025)*
- **Pasar note-taking apps** menunjukkan pertumbuhan dengan tren integrasi AI
- **Gemini 2.5 Flash** dipilih sebagai model "price-performance" terbaik untuk low-latency tasks
### Diferensiasi NotesAI
🎯 **AI Contextual** - AI dapat membaca semua catatan sebagai konteks
🎯 **Document to Summary** - Upload file langsung dapat ringkasan
🎯 **Local-First** - Tidak butuh login, data tersimpan lokal
🎯 **Free & Open** - Tidak ada paywall untuk fitur utama
---
## 🎨 Desain UI/UX
### Design System
- **Material Design 3** - Modern, clean, consistent
- **Color Scheme** - Dynamic gradients untuk kategori
- **Typography** - Clear hierarchy untuk readability
- **Spacing** - Consistent 4dp baseline grid
### User Flow
```
┌─────────────────────────────────────────────┐
│ 🏠 Main Screen (Home) │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Category │ │ Category │ │
│ │ Card │ │ Card │ │
│ └─────────────┘ └─────────────┘ │
└───────────┬─────────────────────────────────┘
│ Select Category
┌─────────────────────────────────────────────┐
│ 📄 Notes List Screen │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Note Card │ │ Note Card │ │
│ │ (Pinned) │ │ (Regular) │ │
│ └─────────────┘ └─────────────┘ │
└───────────┬─────────────────────────────────┘
│ Open Note
┌─────────────────────────────────────────────┐
│ ✏️ Full-Screen Editor │
│ • Rich Text Toolbar (Draggable) │
│ • Bold, Italic, Underline │
│ • Heading, Bullet List │
│ • Auto-save on background │
└─────────────────────────────────────────────┘
```
### Wireframe & Mockup
📐 **Wireframe lengkap** tersedia di [Dokumentasi](docs/Laporan%20Dokumentasi%20Aplikasi%20-%20Kelompok%201.pdf) Halaman 15
📸 **Screenshot aplikasi** tersedia di Panduan Pengguna (Halaman 21-28)
---
## 🛠️ Teknologi dan Alat
### Tech Stack
#### Core Technologies
```
// Build Configuration
Kotlin 1.9.0
Android Gradle Plugin 8.2.0
Compile SDK 34
Min SDK 24 (Android 7.0)
Target SDK 34
```
#### UI & Architecture
- **Jetpack Compose** - Modern declarative UI
- **Material 3** - Latest Material Design components
- **Navigation Compose** - Type-safe navigation
- **Lifecycle** - Lifecycle-aware components
#### Data & Storage
- **DataStore Preferences** - Key-value storage
- **Kotlinx Serialization** - JSON serialization
- **Kotlin Coroutines** - Asynchronous programming
- **Flow** - Reactive data streams
#### AI & Integration
- **Gemini API** - Google Generative AI (Gemini 2.5 Flash)
- **PDFBox-Android** - PDF text extraction
- **Activity Result API** - File picker for document upload
#### Development Tools
- **Android Studio**
- **Git** - Version control (git.lab.ubharajaya.ac.id)
- **Gradle** - Build automation
- **Claude AI** - AI-assisted development
### Dependencies
```gradle
dependencies {
// Compose
implementation("androidx.compose.ui:ui:1.6.0")
implementation("androidx.compose.material3:material3:1.2.0")
// DataStore
implementation("androidx.datastore:datastore-preferences:1.0.0")
// Serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
// AI
implementation("com.google.ai.client.generativeai:generativeai:0.1.2")
// PDF Parser
implementation("com.tom-roush:pdfbox-android:2.0.27.0")
// Testing
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
}
```
---
## 🏗️ Arsitektur Aplikasi
### Architecture Pattern
```
┌──────────────────────────────────────────────────┐
│ PRESENTATION LAYER │
│ ┌──────────────────────────────────────────┐ │
│ │ Composable Screens │ │
│ │ • MainScreen │ │
│ │ • AIHelperScreen │ │
│ │ • ArchiveScreen, TrashScreen │ │
│ └──────────────────────────────────────────┘ │
└────────────────────┬─────────────────────────────┘
│ Uses
┌──────────────────────────────────────────────────┐
│ DATA LAYER │
│ ┌──────────────────────────────────────────┐ │
│ │ DataStoreManager │ │
│ │ • saveNotes() / notesFlow │ │
│ │ • saveCategories() / categoriesFlow │ │
│ │ • saveChatHistory() / chatHistoryFlow │ │
│ └──────────────────────────────────────────┘ │
└────────────────────┬─────────────────────────────┘
│ Stores
┌──────────────────────────────────────────────────┐
│ MODEL LAYER │
│ • Note (id, title, content, isPinned...) │
│ • Category (id, name, gradients, isPinned...) │
│ • ChatHistory (messages, timestamp...) │
└──────────────────────────────────────────────────┘
```
### Package Structure
```
com.example.notesai/
├── 📁 config/
│ └── APIKey.kt
├── 📁 data/
│ ├── 📁 local/
│ │ └── DataStoreManager.kt
│ └── 📁 model/
│ ├── Note.kt
│ ├── Category.kt
│ ├── ChatHistory.kt
│ └── ChatMessage.kt
├── 📁 presentation/
│ ├── 📁 components/
│ │ ├── DrawerMenu.kt
│ │ ├── ModernTopBar.kt
│ │ └── ModernBottomBar.kt
│ └── 📁 screens/
│ ├── 📁 main/
│ ├── 📁 ai/
│ ├── 📁 archive/
│ ├── 📁 trash/
│ └── 📁 note/
└── 📁 util/
├── FileParser.kt
├── Constants.kt
└── AppColors.kt
```
---
## 📚 Resource yang Digunakan
### Visual Assets
- 🎨 **Icons** - Material Icons & Lucide Icons
- 🌈 **Colors** - Material 3 Dynamic Color
- 🖼️ **Illustrations** - Custom empty states
### Content & Data
- 📖 **Sample Data** - Test categories & notes untuk demo
- 📄 **Documents** - Sample PDF/TXT untuk testing parser
### External Services
- 🤖 **Gemini API** - Google Generative AI
- 📚 **Documentation** - Android Developers, Kotlin Docs
### Learning Resources
Referensi utama yang digunakan:
- [Android App Architecture Guide](https://developer.android.com/topic/architecture)
- [Jetpack Compose Documentation](https://developer.android.com/jetpack/compose)
- [Gemini API Documentation](https://ai.google.dev/docs)
- [Kotlin Serialization](https://kotlinlang.org/docs/serialization.html)
---
## 🧪 Pengujian Aplikasi
### Metodologi Testing
**Primary Method:** Black-Box Functional Testing
**Supporting Method:** Automated Unit Testing
Pengujian dilakukan menggunakan metode **Black-Box Functional Testing** sebagai pendekatan utama, dimana setiap fitur divalidasi dari perspektif end-user dengan memverifikasi kesesuaian **Expected vs Actual Result**. Didukung oleh **59 automated unit tests** untuk validasi business logic internal.
### Test Coverage Summary
| Test Case | Fitur | Tests | Status |
|-----------|-------|-------|--------|
| **TC-01** | Create Note & Category + Autosave | 8 tests | ✅ PASSED |
| **TC-02** | Pin Note (Priority) | included | ✅ PASSED |
| **TC-03** | Soft Delete & Restore | 11 tests | ✅ PASSED |
| **TC-04** | Search Realtime | 14 tests | ✅ PASSED |
| **TC-05** | AI Chat with Context | 14 tests | ✅ PASSED |
| **TC-06** | Upload PDF → Summary | 12 tests | ✅ PASSED |
| **TOTAL** | **6 Test Cases** | **59 tests** | **✅ 100%** |
### Test Results
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 TEST SUMMARY REPORT
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total Test Cases: 6
Passed Test Cases: 6
Failed Test Cases: 0
Success Rate: 100%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total Unit Tests: 59
Passed Tests: 59
Failed Tests: 0
Execution Time: ~2 minutes
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Status: ✅ ALL TESTS PASSED
Quality: ✅ PRODUCTION READY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
📄 **Laporan lengkap:** [TEST_SUMMARY_REPORT.md](./TEST_SUMMARY_REPORT.md)
### Testing Framework
- **JUnit 4** - Unit testing framework
- **AndroidX Test** - Android testing utilities
- **Kotlin Coroutines Test** - Async testing
- **Truth** - Assertion library
---
## 🚀 Instalasi dan Penggunaan
### Prasyarat
- ✅ Android 7.0 (API 24) atau lebih tinggi
- ✅ Koneksi internet (untuk fitur AI)
- ✅ Minimal 50MB storage kosong
### Cara Menjalankan dari Source Code
#### 1. Clone Repository
```bash
git clone https://git.lab.ubharajaya.ac.id/kelompok-3/notesai.git
cd notesai
```
#### 2. Setup API Key
Buat file `local.properties` di root project:
```properties
GEMINI_API_KEY=your_gemini_api_key_here
```
#### 3. Open di Android Studio
1. Buka Android Studio
2. File → Open → Pilih folder project
3. Tunggu Gradle sync selesai
#### 4. Run Aplikasi
1. Pilih device/emulator
2. Klik Run (▶️) atau `Shift + F10`
3. Aplikasi akan terinstall dan berjalan
---
## 📱 Panduan Penggunaan
### Quick Start Guide
#### 1⃣ Membuat Kategori Pertama
```
Main Screen → Tap () → Pilih "Kategori Baru"
→ Isi nama kategori → Pilih warna → Save
```
#### 2⃣ Membuat Note
```
Main Screen → Tap kategori → Tap () floating button
→ Isi judul & konten → Auto-saved ✓
```
#### 3⃣ Menggunakan Rich Text Editor
```
Buka note → Tap area teks → Muncul draggable toolbar
→ Pilih format (Bold/Italic/Heading/Bullet) → Type away!
```
#### 4⃣ Pin untuk Prioritas
```
Long-press note → Tap ⭐ Pin icon
→ Note akan muncul di urutan teratas
```
#### 5⃣ Chat dengan AI
```
Drawer Menu → AI Assistant → Ketik pertanyaan
→ AI akan menjawab berdasarkan catatan Anda
```
#### 6⃣ Upload & Summarize Document
```
AI Assistant → Tap 📎 Upload → Pilih file (PDF/TXT/DOCX)
→ AI otomatis generate summary → Tersimpan di chat history
```
### User Flow Lengkap
📖 Panduan detail dengan screenshot tersedia di [Dokumentasi](./docs/Laporan%20Dokumentasi%20Aplikasi%20-%20Kelompok%201.pdf) Bab III (Halaman 21-28)
---
## ⚠️ Batasan dan Catatan
### Keterbatasan Saat Ini
1. **AI Dependency**
- ⚠️ Fitur AI memerlukan koneksi internet
- ⚠️ Menggunakan free tier Gemini API (rate limited)
- Catatan lokal tetap berfungsi offline
2. **Document Format**
- ✅ Support: PDF, TXT, DOCX
- ❌ Tidak support: XLS, PPT, Images
3. **Data Storage**
- 💾 Data tersimpan lokal (DataStore)
- ⚠️ Tidak ada cloud backup (planned v2.0)
- Risiko data loss jika uninstall app
4. **Performance**
- ⚡ Optimal untuk <1000 notes
- ⚠️ Search dapat melambat pada dataset besar
- 🔜 Indexing optimization planned
### Privasi & Keamanan
- ✅ Catatan disimpan **100% lokal**
- ⚠️ Saat menggunakan AI, konten relevan dikirim ke Gemini API
- 🔐 API key tidak hardcoded (menggunakan BuildConfig)
- Tidak ada tracking atau analytics
---
## 🔮 Roadmap & Future Development
### Version 1.2.0 (Q2 2025) 🎯
- [ ] **Cloud Sync** - Firebase/Supabase integration
- [ ] **Backup & Restore** - Export/import data
- [ ] **Widget** - Home screen quick note
- [ ] **Reminder** - Notification untuk note penting
- [ ] **Templates** - Pre-made note templates
### Version 1.3.0 (Q3 2025) 🚀
- [ ] **Collaboration** - Share notes dengan user lain
- [ ] **Voice Input** - Speech-to-text untuk note
- [ ] **Image Support** - Attach images ke notes
- [ ] **Tag System** - Alternative categorization
- [ ] **Advanced Search** - Filter by date, tag, etc.
### Version 1.4.0 (Q4 2025) 💎
- [ ] **Multi-device Sync** - Real-time sync
- [ ] **Encryption** - End-to-end encryption
- [ ] **Premium AI** - Upgrade ke Gemini Pro
- [ ] **Offline AI** - On-device AI model
- [ ] **iOS Version** - Cross-platform support
---
## 📄 Dokumentasi Tambahan
### File Dokumentasi
- 📖 [Laporan Lengkap](./docs/Laporan%20Dokumentasi%20Aplikasi%20-%20Kelompok%201.pdf) - Dokumentasi lengkap 34 halaman
- 🧪 [Test Summary Report](./TEST_SUMMARY_REPORT.md) - Laporan pengujian detail
- 📋 [Changelog](./CHANGELOG.md) - Riwayat perubahan versi
### API Documentation
- 🤖 [Gemini API Docs](https://ai.google.dev/docs)
- 📚 [Android Developers](https://developer.android.com)
- 📝 [Kotlin Documentation](https://kotlinlang.org/docs)
### Referensi Akademik
Semua referensi dan kutipan tercantum di [Daftar Pustaka](./docs/Laporan%20Dokumentasi%20Aplikasi%20-%20Kelompok%201.pdf) halaman 33
---
## 🤝 Kontribusi & Support
### Cara Berkontribusi
1. Fork repository ini
2. Buat branch fitur (`git checkout -b feature/AmazingFeature`)
3. Commit changes (`git commit -m 'Add some AmazingFeature'`)
4. Push ke branch (`git push origin feature/AmazingFeature`)
5. Buat Pull Request
### Coding Standards
- ✅ Follow Kotlin coding conventions
- ✅ Write descriptive commit messages
- ✅ Add unit tests untuk fitur baru
- ✅ Update documentation
### Laporkan Bug
Jika menemukan bug, silakan buat issue dengan:
- 📝 Deskripsi bug
- 📱 Device & Android version
- 🔄 Steps to reproduce
- 📸 Screenshot (jika ada)
---
## 🙏 Acknowledgments
### Special Thanks
- 🎓 **Bapak Arif Rifai Dwiyanto, ST., MTI** - Dosen pembimbing dan pengampu mata kuliah
- 🏫 **Universitas Bhayangkara Jakarta Raya** - Dukungan fasilitas
- 🤖 **Claude AI (Anthropic)** - AI assistant untuk pengembangan dan debugging
- 🎨 **Material Design Team** - Design system yang digunakan
- 📚 **Android Developer Community** - Dokumentasi dan best practices
### Tools & Services
- Android Studio - IDE terbaik untuk Android development
- Jetpack Compose - Modern UI toolkit
- Gemini API - AI capabilities
- PDFBox - PDF parsing library
- Git Lab UBHARA - Version control hosting
---
## 📞 Kontak
**Tim Pengembang Kelompok 1**
📧 Email:
1. [202310715297@mhs.ubharajaya.ac.id](mailto:202310715297@mhs.ubharajaya.ac.id) (Raihan Ariq Muzakki)
2. [202310715051@mhs.ubharajaya.ac.id](mailto:202310715051@mhs.ubharajaya.ac.id) (Dendi Yogia Pratama)
3. [202310715082@mhs.ubharajaya.ac.id](mailto:202310715082@mhs.ubharajaya.ac.id) (Fazri Abdurrahman)
🌐 Repository: [NotesAI](https://git.lab.ubharajaya.ac.id/202310715297-RAIHAN-ARIQ-MUZAKKI/NotesAI.git)
🏫 Institusi: Universitas Bhayangkara Jakarta Raya
---
<div align="center">
**Made with ❤️ by Kelompok 1**
**Fakultas Ilmu Komputer - Program Studi Informatika**
**Universitas Bhayangkara Jakarta Raya**
**2025**
</div>

115
Readme.md Normal file
View File

@ -0,0 +1,115 @@
---
# **AI Notes Changelog**
## **Tim Pengembang**
* Dendi Yogia Pratama
---
# **Version 1.0.0 Initial Release**
---
## **Sprint 1: Struktur Dasar Aplikasi**
* Implementasi struktur navigasi dasar aplikasi
* Pembuatan menu drawer untuk navigasi screen
* Pembuatan screen Arsip dan Sampah
* Implementasi routing antar halaman (Beranda, Arsip, Sampah)
* Penambahan Bottom Navigation (Home & AI Helper)
* Penambahan Top App Bar dengan menu dan search
* Setup Material3 dengan Dark Theme
* Implementasi color scheme & gradient header
* Pembuatan data class: Category, Note, ChatMessage
* Implementasi sistem kategori pada halaman beranda
* Pembuatan dialog tambah kategori (nama + gradient picker)
* Penambahan validasi input form kategori
* Tampilan kategori Staggered Grid (2 kolom)
* Category Card (ikon folder, nama, jumlah catatan, gradient)
* Long press untuk menghapus kategori
* Empty state kategori
* Implementasi LazyVerticalStaggeredGrid
* Gradient preset 8 warna
* Manajemen state kategori
* Implementasi pembuatan dan pengeditan catatan
* Dialog catatan (judul, isi, simpan, batal, hapus)
* Note Card (judul, preview, timestamp, pin/unpin)
* Fitur pin untuk catatan penting
* Full-screen editable note view dengan auto-save
* Fitur arsip, hapus, dan pin di full-screen mode
* Long press untuk mengarsipkan catatan
* Fitur search catatan (judul + isi)
* Sorting catatan berdasarkan pin & timestamp
* Implementasi custom TextField dan date formatter
* Edit in-place full-screen note
* Pembuatan screen AI Helper
* Header AI dengan ikon bintang & badge Gemini
* Category selector untuk filter konteks AI
* Statistik ringkas (total, pinned, kategori)
* Welcome state dengan icon + greeting
* Suggestion chips untuk pertanyaan cepat
* Input area multiline dengan tombol kirim gradient
* Auto-scroll menggunakan LaunchedEffect
* State management chat messages
* Integrasi Gemini 2.5 Flash API
* Implementasi prompt engineering menggunakan data catatan
* Chat bubble user & AI
* Copy-to-clipboard untuk jawaban AI
* Loading indicator saat AI memproses
* Error message informatif
* Timestamp pada setiap pesan
* Filter catatan berdasarkan kategori untuk konteks
* Pembatasan 10 catatan terbaru (optimasi token)
* Implementasi Google AI SDK (temperature, topK, topP, token limit)
* Context builder untuk kategori & catatan
* API calls menggunakan coroutine async
* Refinement warna & gradient aplikasi
* Smooth animations (drawer, FAB, transitions)
* Peningkatan shadow dan elevation komponen
* Konsistensi spacing dan padding
* Peningkatan desain Card dengan rounded corners
* Optimasi readability teks
* Visual feedback (klik, copy message, loading states)
* Empty state baru dengan icon & pesan
* Perbaikan error messages dengan ikon dan warna
* State hoisting untuk optimasi recomposition
* Perbaikan smooth scroll & keyboard handling
* Implementasi DataStore sebagai penyimpanan lokal
* Auto-save kategori & catatan dengan debounce (500ms)
* Persistence data penuh setelah app ditutup
* Error handling read/write DataStore
* Flow-based data loading menggunakan LaunchedEffect
* Implementasi DataStoreManager (categoriesFlow & notesFlow)
* Try-catch semua operasi I/O
* Optimasi lifecycle data
---
## **Fitur Utama Aplikasi**
* Sistem kategori dengan gradient
* Buat/edit/hapus catatan
* Pin catatan penting
* Full-screen editor
* Search catatan
* Arsip & Sampah dengan restore/delete permanen
* AI Chat powered by Gemini
* AI membaca & menganalisis catatan pengguna
* Suggestion chips & copy response
* Filter AI berdasarkan kategori
* Dark theme modern + gradient
* Animasi smooth
* Empty states & error handling
---
## **Planned Features (v1.1.0)**
* Backup & restore data
* Tags untuk catatan
* Rich text editor
* Dark theme toggle
* Multi-language support
---

View File

@ -1,150 +0,0 @@
## Functional Testing (Unit Testing)
# Test Summary Report - NotesAI App
**Project:** NotesAI - Note Taking Application with AI Assistant
**Test Date:** December 2024
**Tester:** QA Team
**Total Test Cases:** 6
**Total Unit Tests:** 59
**Status:** ✅ ALL PASSED
Pengujian fungsional dilakukan secara manual dengan metode black-box berbasis test case,
didukung oleh Automated Unit Tests, memverifikasi kesesuaian expected vs actual result pada fitur inti
(notes, kategori, pin, trash/restore, search, AI context, dan upload-summary).
Unit testing adalah pengujian otomatis terhadap unit terkecil dari kode
(functions, methods) untuk memvalidasi logic internal aplikasi.
---
## Detailed Test Results
### TC-01 & TC-02: Note & Category Management (8 tests)
**File:** `DataStoreManagerTest.kt`
**Status:** ✅ 8/8 PASSED
| Test Method | Description | Status |
|-------------|-------------|--------|
| `testCreateCategory_shouldSaveSuccessfully` | Membuat category baru | ✅ PASSED |
| `testCreateNote_shouldSaveSuccessfully` | Membuat note baru | ✅ PASSED |
| `testCreateMultipleCategories_shouldSaveInCorrectOrder` | Multiple categories | ✅ PASSED |
| `testAutoSave_shouldUpdateExistingNote` | Autosave dengan debounce 500ms | ✅ PASSED |
| `testPinNote_shouldAppearFirst` | Pinned note muncul pertama | ✅ PASSED |
| `testMultiplePinnedNotes_shouldSortByTimestamp` | Multiple pinned notes sorting | ✅ PASSED |
| `testUnpinNote_shouldMoveToNormalPosition` | Unpin note ke posisi normal | ✅ PASSED |
| `testPinCategory_shouldPersist` | Pin category persist | ✅ PASSED |
---
### TC-03: Trash & Restore (11 tests)
**File:** `TrashFunctionalityTest.kt`
**Status:** ✅ 11/11 PASSED
| Test Method | Description | Status |
|-------------|-------------|--------|
| `testSoftDeleteNote_shouldMarkAsDeleted` | Soft delete note | ✅ PASSED |
| `testRestoreNoteFromTrash_shouldUnmarkDeleted` | Restore note dari trash | ✅ PASSED |
| `testSoftDeleteCategory_shouldMarkAsDeleted` | Soft delete category | ✅ PASSED |
| `testRestoreCategoryFromTrash_shouldUnmarkDeleted` | Restore category dari trash | ✅ PASSED |
| `testFilterDeletedNotes_shouldOnlyShowDeleted` | Filter deleted notes | ✅ PASSED |
| `testFilterDeletedCategories_shouldOnlyShowDeleted` | Filter deleted categories | ✅ PASSED |
| `testPermanentDeleteNote_shouldRemoveCompletely` | Permanent delete note | ✅ PASSED |
| `testPermanentDeleteCategory_shouldRemoveCompletely` | Permanent delete category | ✅ PASSED |
| `testSearchInTrash_shouldFindDeletedItems` | Search di trash | ✅ PASSED |
| `testRestoreMultipleNotes_shouldRestoreAll` | Restore multiple notes | ✅ PASSED |
| `testDeletedNotePreservesAllData_shouldKeepContent` | Data preserved saat deleted | ✅ PASSED |
---
### TC-04: Search Functionality (14 tests)
**File:** `SearchFunctionalityTest.kt`
**Status:** ✅ 14/14 PASSED
| Test Method | Description | Status |
|-------------|-------------|--------|
| `testSearchNoteByTitle_shouldFindMatches` | Search by title | ✅ PASSED |
| `testSearchNoteByContent_shouldFindMatches` | Search by content | ✅ PASSED |
| `testSearchCaseInsensitive_shouldFindMatches` | Case-insensitive search | ✅ PASSED |
| `testSearchPartialMatch_shouldFindResults` | Partial keyword match | ✅ PASSED |
| `testSearchEmptyQuery_shouldReturnAllNotes` | Empty query return all | ✅ PASSED |
| `testSearchNoMatches_shouldReturnEmpty` | No matches return empty | ✅ PASSED |
| `testSearchExcludesDeletedNotes_shouldNotFindDeleted` | Exclude deleted notes | ✅ PASSED |
| `testSearchExcludesArchivedNotes_shouldNotFindArchived` | Exclude archived notes | ✅ PASSED |
| `testSearchCategory_shouldFindByName` | Search category by name | ✅ PASSED |
| `testSearchCategoryPartialMatch_shouldFind` | Category partial match | ✅ PASSED |
| `testSearchMultipleKeywords_shouldFindAll` | Multiple keyword matches | ✅ PASSED |
| `testSearchRealtime_shouldUpdateImmediately` | Realtime update | ✅ PASSED |
| `testSearchWithSpecialCharacters_shouldHandle` | Handle special characters | ✅ PASSED |
| `testSearchFilteredByCategory_shouldOnlySearchInCategory` | Search dalam category | ✅ PASSED |
---
### TC-05: AI Chat with Context (14 tests)
**File:** `AIChatFunctionalityTest.kt`
**Status:** ✅ 14/14 PASSED
| Test Method | Description | Status |
|-------------|-------------|--------|
| `testBuildNotesContext_shouldIncludeAllNotes` | Build context dengan notes | ✅ PASSED |
| `testBuildNotesContext_shouldFilterByCategory` | Filter context by category | ✅ PASSED |
| `testBuildNotesContext_shouldExcludeArchivedNotes` | Exclude archived notes | ✅ PASSED |
| `testSaveChatHistory_shouldPersist` | Save chat history | ✅ PASSED |
| `testLoadChatHistory_shouldRestoreMessages` | Load chat history | ✅ PASSED |
| `testChatPreview_shouldTruncateLongMessages` | Truncate long preview | ✅ PASSED |
| `testMultipleChatHistories_shouldSortByTimestamp` | Sort histories by timestamp | ✅ PASSED |
| `testUpdateChatHistory_shouldUpdateExisting` | Update existing chat | ✅ PASSED |
| `testDeleteChatHistory_shouldMarkAsDeleted` | Soft delete chat history | ✅ PASSED |
| `testCustomChatTitle_shouldPersist` | Custom title persist | ✅ PASSED |
| `testUpdateChatTitle_shouldUpdate` | Update chat title | ✅ PASSED |
| `testChatWithContext_shouldBuildCorrectPrompt` | Build prompt with context | ✅ PASSED |
| `testChatMessageConversion_shouldPreserveData` | Message conversion | ✅ PASSED |
| `testEmptyNotesContext_shouldHandleGracefully` | Handle empty notes | ✅ PASSED |
---
### TC-06: File Upload & Summary (12 tests)
**File:** `FileUploadFunctionalityTest.kt`
**Status:** ✅ 12/12 PASSED
| Test Method | Description | Status |
|-------------|-------------|--------|
| `testFileParseResult_shouldCalculateWordCount` | Calculate word count | ✅ PASSED |
| `testFileParseResult_shouldIdentifyFileType` | Identify file type | ✅ PASSED |
| `testFileParseError_shouldContainMessage` | Error message handling | ✅ PASSED |
| `testFormatFileSize_shouldFormatCorrectly` | Format file size (B/KB/MB) | ✅ PASSED |
| `testSaveSummaryToChatHistory_shouldPersist` | Save summary to history | ✅ PASSED |
| `testMultipleFileUploads_shouldTrackAll` | Track multiple uploads | ✅ PASSED |
| `testSummaryContent_shouldBeReadable` | Summary readability | ✅ PASSED |
| `testFileUploadError_shouldHandleGracefully` | Handle upload errors | ✅ PASSED |
| `testPDFSummaryFormat_shouldBeStructured` | Structured summary format | ✅ PASSED |
| `testSearchInSummaries_shouldFindKeywords` | Search in summaries | ✅ PASSED |
| `testLongSummary_shouldTruncatePreview` | Truncate long preview | ✅ PASSED |
| `testFileMetadata_shouldBePreserved` | Preserve file metadata | ✅ PASSED |
---
## Test Coverage Summary
| Component | Tests | Passed | Failed | Coverage |
|-----------|-------|--------|--------|----------|
| DataStore Management | 8 | 8 | 0 | 100% |
| Trash & Restore | 11 | 11 | 0 | 100% |
| Search Functionality | 14 | 14 | 0 | 100% |
| AI Chat Context | 14 | 14 | 0 | 100% |
| File Upload & Summary | 12 | 12 | 0 | 100% |
| **TOTAL** | **59** | **59** | **0** | **100%** |
---
## Conclusion
**All 59 unit tests passed successfully**
**100% test coverage** untuk semua fitur utama
**All 6 test cases** memenuhi kriteria acceptance
**Test Environment:**
- Framework: JUnit4 + AndroidX Test
- Coroutines: kotlinx-coroutines-test
- DataStore: androidx.datastore.preferences
- Device: Samsung SM-A127F
---

View File

View File

@ -7,7 +7,7 @@ plugins {
android {
namespace = "com.example.notesai"
compileSdk = 35
compileSdk = 34
defaultConfig {
applicationId = "com.example.notesai"
@ -16,6 +16,8 @@ android {
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
@ -31,102 +33,45 @@ android {
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
excludes += "/META-INF/DEPENDENCIES"
excludes += "/META-INF/LICENSE"
excludes += "/META-INF/LICENSE.txt"
excludes += "/META-INF/license.txt"
excludes += "/META-INF/NOTICE"
excludes += "/META-INF/NOTICE.txt"
excludes += "/META-INF/notice.txt"
excludes += "/META-INF/ASL2.0"
excludes += "/META-INF/*.kotlin_module"
}
}
}
dependencies {
// Core Android
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
// Compose BOM
implementation(platform("androidx.compose:compose-bom:2024.02.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.material:material-icons-extended-android:1.6.7")
// Material Design
implementation("com.google.android.material:material:1.9.0")
// DataStore
implementation("androidx.datastore:datastore-preferences:1.0.0")
// Serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
// Gemini AI
implementation("com.google.ai.client.generativeai:generativeai:0.9.0")
// Untuk integrasi Gemini AI (optional - uncomment jika sudah ada API key)
// implementation("com.google.ai.client.generativeai:generativeai:0.1.2")
// Version Catalog (libs)
implementation(libs.androidx.ui.text)
implementation(libs.androidx.material3)
implementation(libs.androidx.animation.core)
implementation(libs.androidx.glance)
implementation(libs.androidx.animation)
implementation(libs.androidx.ui.graphics)
// File operations
implementation("androidx.documentfile:documentfile:1.0.1")
// PDF Parser
implementation("com.tom-roush:pdfbox-android:2.0.27.0")
implementation(libs.androidx.junit.ktx)
// Debug
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
// Testing dependencies - TAMBAHKAN INI
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
// AndroidX Test - Core library
androidTestImplementation("androidx.test:core:1.5.0")
androidTestImplementation("androidx.test:core-ktx:1.5.0")
// AndroidX Test - Rules
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test:runner:1.5.2")
// Coroutines Test
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
// DataStore Testing
androidTestImplementation("androidx.datastore:datastore-preferences:1.0.0")
// Truth (optional, untuk assertion yang lebih baik)
testImplementation("com.google.truth:truth:1.1.5")
androidTestImplementation("com.google.truth:truth:1.1.5")
androidTestImplementation(platform("androidx.compose:compose-bom:2024.02.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}

View File

@ -1,519 +0,0 @@
package com.example.notesai
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.notesai.data.local.DataStoreManager
import com.example.notesai.data.model.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
import java.util.UUID
/**
* Unit Test untuk AI Chat Functionality
* Coverage:
* - TC-05: AI chat menjawab dengan konteks note (gunakan 1-2 contoh note)
*/
@RunWith(AndroidJUnit4::class)
class AIChatFunctionalityTest {
private lateinit var context: Context
private lateinit var dataStore: DataStore<Preferences>
private lateinit var dataStoreManager: DataStoreManager
private lateinit var testScope: CoroutineScope
@Before
fun setup() = runBlocking {
context = ApplicationProvider.getApplicationContext()
testScope = CoroutineScope(SupervisorJob())
val testDataStoreName = "test_ai_chat_prefs_${UUID.randomUUID()}"
dataStore = PreferenceDataStoreFactory.create(
scope = testScope,
produceFile = { context.preferencesDataStoreFile(testDataStoreName) }
)
dataStoreManager = DataStoreManager(context)
// Clear all data before each test
dataStoreManager.saveNotes(emptyList())
dataStoreManager.saveCategories(emptyList())
dataStoreManager.saveChatHistory(emptyList())
}
@After
fun tearDown() {
testScope.cancel()
}
// ================== TC-05: AI CHAT WITH CONTEXT ==================
@Test
fun testBuildNotesContext_shouldIncludeAllNotes() = runBlocking {
// Given - Create sample notes
val notes = listOf(
Note(
id = "note_001",
categoryId = "cat_work",
title = "Project Meeting",
content = "Discussed Q4 goals and timeline for new features",
isArchived = false,
isDeleted = false
),
Note(
id = "note_002",
categoryId = "cat_work",
title = "Technical Specs",
content = "API design for user authentication module",
isArchived = false,
isDeleted = false
)
)
dataStoreManager.saveNotes(notes)
// When - Build context (simulating AIHelperScreen context building)
val savedNotes = dataStoreManager.notesFlow.first()
val filteredNotes = savedNotes.filter { !it.isArchived && !it.isDeleted }
val notesContext = buildString {
appendLine("Data catatan pengguna:")
appendLine("Total catatan: ${filteredNotes.size}")
appendLine()
appendLine("Daftar catatan:")
filteredNotes.forEach { note ->
appendLine("- Judul: ${note.title}")
appendLine(" Isi: ${note.content.take(100)}")
appendLine()
}
}
// Then - Context should contain both notes
assertTrue(notesContext.contains("Total catatan: 2"))
assertTrue(notesContext.contains("Project Meeting"))
assertTrue(notesContext.contains("Technical Specs"))
assertTrue(notesContext.contains("Discussed Q4 goals"))
assertTrue(notesContext.contains("API design"))
}
@Test
fun testBuildNotesContext_shouldFilterByCategory() = runBlocking {
// Given - Notes in different categories
val notes = listOf(
Note(id = "note_001", categoryId = "cat_work", title = "Work Note", content = "Work content", isArchived = false),
Note(id = "note_002", categoryId = "cat_personal", title = "Personal Note", content = "Personal content", isArchived = false),
Note(id = "note_003", categoryId = "cat_work", title = "Another Work", content = "More work", isArchived = false)
)
dataStoreManager.saveNotes(notes)
// When - Build context for specific category
val savedNotes = dataStoreManager.notesFlow.first()
val selectedCategoryId = "cat_work"
val filteredNotes = savedNotes.filter {
it.categoryId == selectedCategoryId && !it.isArchived && !it.isDeleted
}
val notesContext = buildString {
appendLine("Data catatan pengguna:")
appendLine("Total catatan: ${filteredNotes.size}")
appendLine("Kategori: Work")
appendLine()
filteredNotes.forEach { note ->
appendLine("- Judul: ${note.title}")
appendLine(" Isi: ${note.content}")
}
}
// Then - Should only include work category notes
assertTrue(notesContext.contains("Total catatan: 2"))
assertTrue(notesContext.contains("Work Note"))
assertTrue(notesContext.contains("Another Work"))
assertFalse(notesContext.contains("Personal Note"))
}
@Test
fun testBuildNotesContext_shouldExcludeArchivedNotes() = runBlocking {
// Given - Mix of archived and active notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Active Note", content = "Active", isArchived = false),
Note(id = "note_002", categoryId = "cat_001", title = "Archived Note", content = "Archived", isArchived = true),
Note(id = "note_003", categoryId = "cat_001", title = "Another Active", content = "Active", isArchived = false)
)
dataStoreManager.saveNotes(notes)
// When - Build context excluding archived
val savedNotes = dataStoreManager.notesFlow.first()
val filteredNotes = savedNotes.filter { !it.isArchived && !it.isDeleted }
val notesContext = buildString {
appendLine("Total catatan: ${filteredNotes.size}")
filteredNotes.forEach { note ->
appendLine("- ${note.title}")
}
}
// Then - Should exclude archived notes
assertTrue(notesContext.contains("Total catatan: 2"))
assertTrue(notesContext.contains("Active Note"))
assertTrue(notesContext.contains("Another Active"))
assertFalse(notesContext.contains("Archived Note"))
}
@Test
fun testSaveChatHistory_shouldPersist() = runBlocking {
// Given - Clear existing data first
dataStoreManager.saveChatHistory(emptyList())
// Chat messages
val messages = listOf(
ChatMessage(id = "msg_001", message = "Apa isi catatan saya?", isUser = true),
ChatMessage(id = "msg_002", message = "Anda memiliki 3 catatan tentang project meeting", isUser = false)
)
val chatHistory = ChatHistory(
id = "chat_001",
categoryId = "cat_work",
categoryName = "Work",
messages = messages.map { it.toSerializable() },
lastMessagePreview = "Anda memiliki 3 catatan...",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
// When - Save chat history
dataStoreManager.addChatHistory(chatHistory)
// Then - Should be saved and retrievable
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals(1, savedHistories.size)
assertEquals("chat_001", savedHistories[0].id)
assertEquals("Work", savedHistories[0].categoryName)
assertEquals(2, savedHistories[0].messages.size)
}
@Test
fun testLoadChatHistory_shouldRestoreMessages() = runBlocking {
// Given - Saved chat history
val messages = listOf(
ChatMessage(id = "msg_001", message = "Berapa banyak catatan saya?", isUser = true),
ChatMessage(id = "msg_002", message = "Anda memiliki 5 catatan", isUser = false),
ChatMessage(id = "msg_003", message = "Apa topik utamanya?", isUser = true),
ChatMessage(id = "msg_004", message = "Topik utama adalah project planning", isUser = false)
)
val chatHistory = ChatHistory(
id = "chat_001",
categoryId = null,
categoryName = "Semua Kategori",
messages = messages.map { it.toSerializable() },
lastMessagePreview = "Topik utama adalah project...",
timestamp = System.currentTimeMillis()
)
dataStoreManager.addChatHistory(chatHistory)
// When - Load chat history
val savedHistories = dataStoreManager.chatHistoryFlow.first()
val loadedHistory = savedHistories.first()
val restoredMessages = loadedHistory.messages.map { it.toChatMessage() }
// Then - Messages should be restored correctly
assertEquals(4, restoredMessages.size)
assertEquals("Berapa banyak catatan saya?", restoredMessages[0].message)
assertTrue(restoredMessages[0].isUser)
assertEquals("Anda memiliki 5 catatan", restoredMessages[1].message)
assertFalse(restoredMessages[1].isUser)
}
@Test
fun testChatPreview_shouldTruncateLongMessages() = runBlocking {
// Given - Long message
val longMessage = "Ini adalah pesan yang sangat panjang yang harus dipotong menjadi preview yang lebih pendek untuk ditampilkan di list"
// When - Create preview (simulating toSafeChatPreview function)
val maxLength = 30
val preview = if (longMessage.length > maxLength) {
longMessage.take(maxLength).trim() + "..."
} else {
longMessage.trim()
}
// Then - Should be truncated
assertTrue(preview.length <= maxLength + 3) // +3 for "..."
assertTrue(preview.endsWith("..."))
assertTrue(preview.startsWith("Ini adalah pesan"))
}
@Test
fun testMultipleChatHistories_shouldSortByTimestamp() = runBlocking {
// Given - Clear existing data first
dataStoreManager.saveChatHistory(emptyList())
// Multiple chat histories with different timestamps
val now = System.currentTimeMillis()
val histories = listOf(
ChatHistory(
id = "chat_001",
categoryId = null,
categoryName = "Semua",
messages = listOf(ChatMessage(message = "Old chat", isUser = true).toSerializable()),
lastMessagePreview = "Old chat",
timestamp = now - 3000,
isDeleted = false
),
ChatHistory(
id = "chat_002",
categoryId = null,
categoryName = "Semua",
messages = listOf(ChatMessage(message = "Recent chat", isUser = true).toSerializable()),
lastMessagePreview = "Recent chat",
timestamp = now - 1000,
isDeleted = false
),
ChatHistory(
id = "chat_003",
categoryId = null,
categoryName = "Semua",
messages = listOf(ChatMessage(message = "Newest chat", isUser = true).toSerializable()),
lastMessagePreview = "Newest chat",
timestamp = now,
isDeleted = false
)
)
// When - Save all histories
histories.forEach { dataStoreManager.addChatHistory(it) }
// Then - Should be sorted by timestamp (newest first)
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals(3, savedHistories.size)
assertEquals("Newest chat", savedHistories[0].lastMessagePreview)
assertEquals("Recent chat", savedHistories[1].lastMessagePreview)
assertEquals("Old chat", savedHistories[2].lastMessagePreview)
}
@Test
fun testUpdateChatHistory_shouldUpdateExisting() = runBlocking {
// Given - Clear existing data first
dataStoreManager.saveChatHistory(emptyList())
// Existing chat history
val initialHistory = ChatHistory(
id = "chat_update_001",
categoryId = "cat_work",
categoryName = "Work",
messages = listOf(
ChatMessage(message = "Hello", isUser = true).toSerializable()
),
lastMessagePreview = "Hello",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(initialHistory)
// When - Update with new messages
val updatedHistory = initialHistory.copy(
messages = initialHistory.messages + ChatMessage(message = "How can I help?", isUser = false).toSerializable(),
lastMessagePreview = "How can I help?"
)
dataStoreManager.addChatHistory(updatedHistory)
// Then - Should update existing history
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals(1, savedHistories.size) // Should still be 1, not 2
assertEquals(2, savedHistories[0].messages.size)
assertEquals("How can I help?", savedHistories[0].lastMessagePreview)
}
@Test
fun testDeleteChatHistory_shouldMarkAsDeleted() = runBlocking {
// Given - Clear existing data first
dataStoreManager.saveChatHistory(emptyList())
// Chat history
val chatHistory = ChatHistory(
id = "chat_delete_001",
categoryId = null,
categoryName = "Semua",
messages = listOf(ChatMessage(message = "Test", isUser = true).toSerializable()),
lastMessagePreview = "Test",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Verify it's saved
val beforeDelete = dataStoreManager.chatHistoryFlow.first()
assertEquals(1, beforeDelete.size)
// When - Delete chat history
dataStoreManager.deleteChatHistory("chat_delete_001")
// Then - Should be filtered out (soft deleted)
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals(0, savedHistories.size)
}
@Test
fun testCustomChatTitle_shouldPersist() = runBlocking {
// Given - Clear existing data first
dataStoreManager.saveChatHistory(emptyList())
// Chat history with custom title
val chatHistory = ChatHistory(
id = "chat_custom_001",
categoryId = null,
categoryName = "Semua",
messages = listOf(ChatMessage(message = "Question", isUser = true).toSerializable()),
lastMessagePreview = "Question",
customTitle = "My Custom Chat Title",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Then - Custom title should be saved
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals(1, savedHistories.size)
assertEquals("My Custom Chat Title", savedHistories[0].customTitle)
}
@Test
fun testUpdateChatTitle_shouldUpdate() = runBlocking {
// Given - Clear existing data first
dataStoreManager.saveChatHistory(emptyList())
// Chat history
val chatHistory = ChatHistory(
id = "chat_title_001",
categoryId = null,
categoryName = "Semua",
messages = listOf(ChatMessage(message = "Test", isUser = true).toSerializable()),
lastMessagePreview = "Test",
customTitle = null,
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// When - Update title
dataStoreManager.updateChatHistoryTitle("chat_title_001", "Updated Title")
// Then - Title should be updated
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals("Updated Title", savedHistories[0].customTitle)
}
@Test
fun testChatWithContext_shouldBuildCorrectPrompt() = runBlocking {
// Given - Sample notes for context
val notes = listOf(
Note(
id = "note_001",
categoryId = "cat_work",
title = "Sprint Planning",
content = "Plan features for next sprint: authentication, dashboard, notifications",
isArchived = false,
isDeleted = false
),
Note(
id = "note_002",
categoryId = "cat_work",
title = "API Design",
content = "REST API endpoints for user management and data sync",
isArchived = false,
isDeleted = false
)
)
dataStoreManager.saveNotes(notes)
// When - Build full prompt with context
val savedNotes = dataStoreManager.notesFlow.first()
val filteredNotes = savedNotes.filter { !it.isArchived && !it.isDeleted }
val notesContext = buildString {
appendLine("Data catatan pengguna:")
appendLine("Total catatan: ${filteredNotes.size}")
appendLine()
appendLine("Daftar catatan:")
filteredNotes.take(10).forEach { note ->
appendLine("- Judul: ${note.title}")
appendLine(" Isi: ${note.content.take(100)}")
appendLine()
}
}
val userPrompt = "Apa yang perlu saya lakukan di sprint berikutnya?"
val fullPrompt = "$notesContext\n\nPertanyaan: $userPrompt\n\nBerikan jawaban dalam bahasa Indonesia yang natural dan membantu."
// Then - Prompt should contain context and question
assertTrue(fullPrompt.contains("Total catatan: 2"))
assertTrue(fullPrompt.contains("Sprint Planning"))
assertTrue(fullPrompt.contains("authentication, dashboard"))
assertTrue(fullPrompt.contains("Pertanyaan: Apa yang perlu saya lakukan"))
}
@Test
fun testChatMessageConversion_shouldPreserveData() = runBlocking {
// Given - Original ChatMessage
val originalMessage = ChatMessage(
id = "msg_001",
message = "Test message content",
isUser = true,
timestamp = 1234567890L
)
// When - Convert to serializable and back
val serializable = originalMessage.toSerializable()
val converted = serializable.toChatMessage()
// Then - All data should be preserved
assertEquals(originalMessage.id, converted.id)
assertEquals(originalMessage.message, converted.message)
assertEquals(originalMessage.isUser, converted.isUser)
assertEquals(originalMessage.timestamp, converted.timestamp)
}
@Test
fun testEmptyNotesContext_shouldHandleGracefully() = runBlocking {
// Given - No notes
dataStoreManager.saveNotes(emptyList())
// When - Build context
val savedNotes = dataStoreManager.notesFlow.first()
val filteredNotes = savedNotes.filter { !it.isArchived && !it.isDeleted }
val notesContext = buildString {
appendLine("Data catatan pengguna:")
appendLine("Total catatan: ${filteredNotes.size}")
if (filteredNotes.isEmpty()) {
appendLine("Belum ada catatan tersimpan.")
}
}
// Then - Should handle empty case
assertTrue(notesContext.contains("Total catatan: 0"))
assertTrue(notesContext.contains("Belum ada catatan"))
}
}

View File

@ -1,370 +0,0 @@
package com.example.notesai
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.notesai.data.local.DataStoreManager
import com.example.notesai.data.model.Category
import com.example.notesai.data.model.Note
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.UUID
/**
* Unit Test untuk DataStoreManager
* Coverage:
* - TC-01: Create note & category + autosave debounce 500ms
* - TC-02: Pin note muncul di urutan teratas
*/
@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(AndroidJUnit4::class)
class DataStoreManagerTest {
private lateinit var context: Context
private lateinit var dataStore: DataStore<Preferences>
private lateinit var dataStoreManager: DataStoreManager
private val testDispatcher = StandardTestDispatcher()
private val testScope = TestScope(testDispatcher + Job())
@Before
fun setup() {
Dispatchers.setMain(testDispatcher)
context = ApplicationProvider.getApplicationContext()
// Create test DataStore with unique name
val testDataStoreName = "test_notes_prefs_${UUID.randomUUID()}"
dataStore = PreferenceDataStoreFactory.create(
scope = testScope,
produceFile = { context.preferencesDataStoreFile(testDataStoreName) }
)
dataStoreManager = DataStoreManager(context)
}
@After
fun tearDown() {
testScope.cancel()
Dispatchers.resetMain()
}
// ================== TC-01: CREATE NOTE & CATEGORY ==================
@Test
fun testCreateCategory_shouldSaveSuccessfully() = testScope.runTest {
// Given
val category = Category(
id = "cat_001",
name = "Work",
gradientStart = 0xFFE91E63,
gradientEnd = 0xFF9C27B0,
timestamp = System.currentTimeMillis(),
isDeleted = false,
isPinned = false
)
// When
dataStoreManager.saveCategories(listOf(category))
advanceUntilIdle()
// Then
val savedCategories = dataStoreManager.categoriesFlow.first()
Assert.assertEquals(1, savedCategories.size)
Assert.assertEquals("Work", savedCategories[0].name)
Assert.assertEquals("cat_001", savedCategories[0].id)
}
@Test
fun testCreateNote_shouldSaveSuccessfully() = testScope.runTest {
// Given
val note = Note(
id = "note_001",
categoryId = "cat_001",
title = "Meeting Notes",
description = "Team meeting summary",
content = "Discussed project timeline",
timestamp = System.currentTimeMillis(),
isPinned = false,
isArchived = false,
isDeleted = false
)
// When
dataStoreManager.saveNotes(listOf(note))
advanceUntilIdle()
// Then
val savedNotes = dataStoreManager.notesFlow.first()
Assert.assertEquals(1, savedNotes.size)
Assert.assertEquals("Meeting Notes", savedNotes[0].title)
Assert.assertEquals("note_001", savedNotes[0].id)
}
@Test
fun testCreateMultipleCategories_shouldSaveInCorrectOrder() = testScope.runTest {
// Given
val categories = listOf(
Category(
id = "cat_001",
name = "Work",
gradientStart = 0xFF000000,
gradientEnd = 0xFF111111
),
Category(
id = "cat_002",
name = "Personal",
gradientStart = 0xFF222222,
gradientEnd = 0xFF333333
),
Category(
id = "cat_003",
name = "Ideas",
gradientStart = 0xFF444444,
gradientEnd = 0xFF555555
)
)
// When
dataStoreManager.saveCategories(categories)
advanceUntilIdle()
// Then
val savedCategories = dataStoreManager.categoriesFlow.first()
Assert.assertEquals(3, savedCategories.size)
Assert.assertEquals("Work", savedCategories[0].name)
Assert.assertEquals("Personal", savedCategories[1].name)
Assert.assertEquals("Ideas", savedCategories[2].name)
}
@Test
fun testAutoSave_shouldUpdateExistingNote() = testScope.runTest {
// Given - Initial note
val initialNote = Note(
id = "note_001",
categoryId = "cat_001",
title = "Draft",
content = "Initial content",
timestamp = System.currentTimeMillis()
)
dataStoreManager.saveNotes(listOf(initialNote))
advanceUntilIdle()
// When - Simulate autosave with updated content (debounce simulation)
val updatedNote = initialNote.copy(
title = "Updated Draft",
content = "Updated content after typing"
)
// Simulate 500ms debounce
delay(500)
dataStoreManager.saveNotes(listOf(updatedNote))
advanceUntilIdle()
// Then
val savedNotes = dataStoreManager.notesFlow.first()
Assert.assertEquals(1, savedNotes.size)
Assert.assertEquals("Updated Draft", savedNotes[0].title)
Assert.assertEquals("Updated content after typing", savedNotes[0].content)
}
// ================== TC-02: PIN NOTE - URUTAN TERATAS ==================
@Test
fun testPinNote_shouldAppearFirst() = testScope.runTest {
// Given - Create 3 notes with different timestamps
val now = System.currentTimeMillis()
val notes = listOf(
Note(
id = "note_001",
categoryId = "cat_001",
title = "Oldest",
timestamp = now - 2000,
isPinned = false
),
Note(
id = "note_002",
categoryId = "cat_001",
title = "Middle",
timestamp = now - 1000,
isPinned = false
),
Note(
id = "note_003",
categoryId = "cat_001",
title = "Newest",
timestamp = now,
isPinned = false
)
)
dataStoreManager.saveNotes(notes)
advanceUntilIdle()
// When - Pin the oldest note
val pinnedNotes = notes.map {
if (it.id == "note_001") it.copy(isPinned = true) else it
}
dataStoreManager.saveNotes(pinnedNotes)
advanceUntilIdle()
// Then - Sort by pinned then timestamp (like in MainScreen.kt)
val savedNotes = dataStoreManager.notesFlow.first()
val sortedNotes = savedNotes
.sortedWith(compareByDescending<Note> { it.isPinned }.thenByDescending { it.timestamp })
Assert.assertEquals("Oldest", sortedNotes[0].title)
Assert.assertTrue(sortedNotes[0].isPinned)
}
@Test
fun testMultiplePinnedNotes_shouldSortByTimestamp() = testScope.runTest {
// Given - Create notes with 2 pinned
val now = System.currentTimeMillis()
val notes = listOf(
Note(
id = "note_001",
categoryId = "cat_001",
title = "Pinned Old",
timestamp = now - 3000,
isPinned = true
),
Note(
id = "note_002",
categoryId = "cat_001",
title = "Normal",
timestamp = now - 2000,
isPinned = false
),
Note(
id = "note_003",
categoryId = "cat_001",
title = "Pinned New",
timestamp = now - 1000,
isPinned = true
),
Note(
id = "note_004",
categoryId = "cat_001",
title = "Newest Normal",
timestamp = now,
isPinned = false
)
)
dataStoreManager.saveNotes(notes)
advanceUntilIdle()
// When - Get sorted notes
val savedNotes = dataStoreManager.notesFlow.first()
val sortedNotes = savedNotes
.sortedWith(compareByDescending<Note> { it.isPinned }.thenByDescending { it.timestamp })
// Then - Pinned notes should be first, sorted by timestamp
Assert.assertEquals(4, sortedNotes.size)
Assert.assertEquals("Pinned New", sortedNotes[0].title) // Pinned, newest
Assert.assertEquals("Pinned Old", sortedNotes[1].title) // Pinned, older
Assert.assertEquals("Newest Normal", sortedNotes[2].title) // Not pinned, newest
Assert.assertEquals("Normal", sortedNotes[3].title) // Not pinned, older
Assert.assertTrue(sortedNotes[0].isPinned)
Assert.assertTrue(sortedNotes[1].isPinned)
Assert.assertFalse(sortedNotes[2].isPinned)
Assert.assertFalse(sortedNotes[3].isPinned)
}
@Test
fun testUnpinNote_shouldMoveToNormalPosition() = testScope.runTest {
// Given - Note that is pinned
val now = System.currentTimeMillis()
val notes = listOf(
Note(
id = "note_001",
categoryId = "cat_001",
title = "Old",
timestamp = now - 2000,
isPinned = false
),
Note(
id = "note_002",
categoryId = "cat_001",
title = "Pinned",
timestamp = now - 1000,
isPinned = true
),
Note(
id = "note_003",
categoryId = "cat_001",
title = "New",
timestamp = now,
isPinned = false
)
)
dataStoreManager.saveNotes(notes)
advanceUntilIdle()
// When - Unpin the note
val unpinnedNotes = notes.map {
if (it.id == "note_002") it.copy(isPinned = false) else it
}
dataStoreManager.saveNotes(unpinnedNotes)
advanceUntilIdle()
// Then - Should be sorted by timestamp only
val savedNotes = dataStoreManager.notesFlow.first()
val sortedNotes = savedNotes
.sortedWith(compareByDescending<Note> { it.isPinned }.thenByDescending { it.timestamp })
Assert.assertEquals("New", sortedNotes[0].title)
Assert.assertEquals("Pinned", sortedNotes[1].title) // Now in middle based on timestamp
Assert.assertEquals("Old", sortedNotes[2].title)
Assert.assertFalse(sortedNotes[0].isPinned)
Assert.assertFalse(sortedNotes[1].isPinned)
Assert.assertFalse(sortedNotes[2].isPinned)
}
@Test
fun testPinCategory_shouldPersist() = testScope.runTest {
// Given
val category = Category(
id = "cat_001",
name = "Important",
gradientStart = 0xFFE91E63,
gradientEnd = 0xFF9C27B0,
isPinned = false
)
dataStoreManager.saveCategories(listOf(category))
advanceUntilIdle()
// When - Pin category
val pinnedCategory = category.copy(isPinned = true)
dataStoreManager.saveCategories(listOf(pinnedCategory))
advanceUntilIdle()
// Then
val savedCategories = dataStoreManager.categoriesFlow.first()
Assert.assertEquals(1, savedCategories.size)
Assert.assertTrue(savedCategories[0].isPinned)
}
}

View File

@ -1,485 +0,0 @@
package com.example.notesai
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.notesai.data.local.DataStoreManager
import com.example.notesai.data.model.ChatHistory
import com.example.notesai.data.model.ChatMessage
import com.example.notesai.data.model.toSerializable
import com.example.notesai.util.FileParseResult
import com.example.notesai.util.FileParser
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
import java.util.UUID
/**
* Unit Test untuk File Upload & PDF Summary Functionality
* Coverage:
* - TC-06: Upload PDF summary tersimpan/terbaca
*/
@RunWith(AndroidJUnit4::class)
class FileUploadFunctionalityTest {
private lateinit var context: Context
private lateinit var dataStore: DataStore<Preferences>
private lateinit var dataStoreManager: DataStoreManager
private lateinit var testScope: CoroutineScope
@Before
fun setup() {
runBlocking {
context = ApplicationProvider.getApplicationContext()
testScope = CoroutineScope(SupervisorJob())
val testDataStoreName = "test_file_upload_prefs_${UUID.randomUUID()}"
dataStore = PreferenceDataStoreFactory.create(
scope = testScope,
produceFile = { context.preferencesDataStoreFile(testDataStoreName) }
)
dataStoreManager = DataStoreManager(context)
// Clear all data before each test
dataStoreManager.saveChatHistory(emptyList())
}
}
@After
fun tearDown() {
testScope.cancel()
}
// ================== TC-06: FILE UPLOAD & SUMMARY ==================
@Test
fun testFileParseResult_shouldCalculateWordCount() {
runBlocking {
// Given - Text with known word count
val content = "One two three four five words here"
val fileResult = FileParseResult.Success(
content = content,
fileName = "word_count_test.txt",
fileType = "Text",
wordCount = content.split(Regex("\\s+")).size
)
// Then - Should count words correctly
assertEquals(7, fileResult.wordCount)
}
}
@Test
fun testFileParseResult_shouldIdentifyFileType() {
runBlocking {
// Given - Different file types
val pdfResult = FileParseResult.Success(
content = "PDF content",
fileName = "test.pdf",
fileType = "PDF",
wordCount = 2
)
val txtResult = FileParseResult.Success(
content = "Text content",
fileName = "test.txt",
fileType = "Text",
wordCount = 2
)
val docxResult = FileParseResult.Success(
content = "Word content",
fileName = "test.docx",
fileType = "Word",
wordCount = 2
)
// Then - Should identify correctly
assertEquals("PDF", pdfResult.fileType)
assertEquals("Text", txtResult.fileType)
assertEquals("Word", docxResult.fileType)
}
}
@Test
fun testFileParseError_shouldContainMessage() {
// Given - Error result
val errorResult = FileParseResult.Error("File kosong atau tidak dapat dibaca")
// Then - Should contain error message
assertEquals("File kosong atau tidak dapat dibaca", errorResult.message)
}
@Test
fun testFormatFileSize_shouldFormatCorrectly() {
// Given - Different file sizes
val testCases = mapOf(
500L to "B",
1024L to "KB",
1024L * 1024 to "MB",
1024L * 1024 * 5 to "MB"
)
// When & Then - Format each size
testCases.forEach { (bytes, expectedUnit) ->
val formatted = FileParser.formatFileSize(bytes)
assertTrue("Expected unit $expectedUnit in $formatted",
formatted.contains(expectedUnit))
}
}
@Test
fun testSaveSummaryToChatHistory_shouldPersist() {
runBlocking {
// Given - Clear existing data
dataStoreManager.saveChatHistory(emptyList())
// Simulate file upload and summary generation
val fileResult = FileParseResult.Success(
content = "This is the content of the uploaded PDF document.",
fileName = "test_document.pdf",
fileType = "PDF",
wordCount = 9
)
// Simulate user message
val userMessage = ChatMessage(
message = "📄 Upload file: ${fileResult.fileName}\n\nMohon buatkan ringkasan dari file ini.",
isUser = true,
timestamp = System.currentTimeMillis()
)
// Simulate AI summary response
val aiSummary = ChatMessage(
message = "Ringkasan dokumen:\n\n1. Poin utama pertama\n2. Poin utama kedua\n3. Kesimpulan",
isUser = false,
timestamp = System.currentTimeMillis()
)
// When - Save to chat history
val chatHistory = ChatHistory(
id = "chat_pdf_001",
categoryId = null,
categoryName = "Semua Kategori",
messages = listOf(userMessage, aiSummary).map { it.toSerializable() },
lastMessagePreview = "Ringkasan dokumen: 1. Poin...",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Then - Should be saved and retrievable
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals(1, savedHistories.size)
assertEquals(2, savedHistories[0].messages.size)
val messages = savedHistories[0].messages
assertTrue(messages[0].message.contains("Upload file"))
assertTrue(messages[0].message.contains("test_document.pdf"))
assertTrue(messages[1].message.contains("Ringkasan dokumen"))
}
}
@Test
fun testMultipleFileUploads_shouldTrackAll() {
runBlocking {
// Given - Clear existing data
dataStoreManager.saveChatHistory(emptyList())
// Multiple file uploads with summaries
val file1Message = ChatMessage(
message = "📄 Upload file: document1.pdf\n\nBuatkan ringkasan.",
isUser = true
)
val summary1 = ChatMessage(
message = "Ringkasan document1: Topik A dan B",
isUser = false
)
val file2Message = ChatMessage(
message = "📄 Upload file: document2.pdf\n\nBuatkan ringkasan.",
isUser = true
)
val summary2 = ChatMessage(
message = "Ringkasan document2: Topik C dan D",
isUser = false
)
// When - Save chat with multiple uploads
val chatHistory = ChatHistory(
id = "chat_multi_pdf",
categoryId = null,
categoryName = "Semua",
messages = listOf(file1Message, summary1, file2Message, summary2).map { it.toSerializable() },
lastMessagePreview = "Ringkasan document2...",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Then - Should track all uploads
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertEquals(4, savedHistories[0].messages.size)
val messages = savedHistories[0].messages
assertTrue(messages[0].message.contains("document1.pdf"))
assertTrue(messages[2].message.contains("document2.pdf"))
}
}
@Test
fun testSummaryContent_shouldBeReadable() {
runBlocking {
// Given - Clear existing data
dataStoreManager.saveChatHistory(emptyList())
// File upload with summary
val fileContent = """
Important Meeting Notes
Topics discussed:
1. Project timeline
2. Budget allocation
3. Team assignments
""".trimIndent()
val summary = """
Ringkasan Meeting Notes:
Topik yang dibahas:
- Timeline proyek
- Alokasi budget
- Penugasan tim
""".trimIndent()
// When - Save chat history
val chatHistory = ChatHistory(
id = "chat_summary_readable",
categoryId = null,
categoryName = "Semua",
messages = listOf(
ChatMessage(message = "Upload: meeting_notes.txt", isUser = true).toSerializable(),
ChatMessage(message = summary, isUser = false).toSerializable()
),
lastMessagePreview = "Ringkasan Meeting Notes...",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Then - Summary should be readable
val savedHistories = dataStoreManager.chatHistoryFlow.first()
val savedSummary = savedHistories[0].messages[1].message
assertTrue(savedSummary.contains("Ringkasan"))
assertTrue(savedSummary.contains("Timeline proyek"))
}
}
@Test
fun testFileUploadError_shouldHandleGracefully() {
runBlocking {
// Given - Clear existing data
dataStoreManager.saveChatHistory(emptyList())
// Error scenario (file too large or unsupported format)
val errorMessage = "⚠️ Gagal membuat ringkasan: File terlalu besar. Maksimal 10MB"
// When - Save error in chat
val chatHistory = ChatHistory(
id = "chat_error",
categoryId = null,
categoryName = "Semua",
messages = listOf(
ChatMessage(message = "Upload file: large_file.pdf", isUser = true).toSerializable(),
ChatMessage(message = errorMessage, isUser = false).toSerializable()
),
lastMessagePreview = "⚠️ Gagal membuat ringkasan...",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Then - Error should be tracked
val savedHistories = dataStoreManager.chatHistoryFlow.first()
assertTrue(savedHistories[0].messages[1].message.contains("Gagal"))
assertTrue(savedHistories[0].messages[1].message.contains("Maksimal 10MB"))
}
}
@Test
fun testPDFSummaryFormat_shouldBeStructured() {
runBlocking {
// Given - Clear existing data
dataStoreManager.saveChatHistory(emptyList())
// Structured PDF summary
val structuredSummary = """
# Ringkasan Dokumen
## Poin Utama
1. **Introduction**: Overview of the topic
2. **Main Content**: Detailed discussion
3. **Conclusion**: Key takeaways
## Rekomendasi
Dokumen ini cocok untuk pembelajaran dasar AI.
""".trimIndent()
// When - Save summary
val chatHistory = ChatHistory(
id = "chat_structured",
categoryId = null,
categoryName = "Semua",
messages = listOf(
ChatMessage(message = "Upload: ai_basics.pdf", isUser = true).toSerializable(),
ChatMessage(message = structuredSummary, isUser = false).toSerializable()
),
lastMessagePreview = "Ringkasan Dokumen...",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Then - Structure should be preserved
val savedHistories = dataStoreManager.chatHistoryFlow.first()
val savedSummary = savedHistories[0].messages[1].message
assertTrue(savedSummary.contains("# Ringkasan Dokumen"))
assertTrue(savedSummary.contains("## Poin Utama"))
assertTrue(savedSummary.contains("## Rekomendasi"))
}
}
@Test
fun testSearchInSummaries_shouldFindKeywords() {
runBlocking {
// Given - Clear existing data
dataStoreManager.saveChatHistory(emptyList())
// Multiple summaries
val summaries = listOf(
ChatHistory(
id = "chat_sum1",
categoryId = null,
categoryName = "Semua",
messages = listOf(
ChatMessage(message = "Upload: kotlin_guide.pdf", isUser = true).toSerializable(),
ChatMessage(message = "Ringkasan: Kotlin adalah bahasa programming modern", isUser = false).toSerializable()
),
lastMessagePreview = "Ringkasan: Kotlin adalah...",
timestamp = System.currentTimeMillis() - 2000,
isDeleted = false
),
ChatHistory(
id = "chat_sum2",
categoryId = null,
categoryName = "Semua",
messages = listOf(
ChatMessage(message = "Upload: java_basics.pdf", isUser = true).toSerializable(),
ChatMessage(message = "Ringkasan: Java adalah bahasa OOP yang populer", isUser = false).toSerializable()
),
lastMessagePreview = "Ringkasan: Java adalah...",
timestamp = System.currentTimeMillis() - 1000,
isDeleted = false
)
)
summaries.forEach { dataStoreManager.addChatHistory(it) }
// When - Search for "Kotlin"
val savedHistories = dataStoreManager.chatHistoryFlow.first()
val searchQuery = "Kotlin"
val searchResults = savedHistories.filter { history ->
history.messages.any { msg ->
msg.message.contains(searchQuery, ignoreCase = true)
}
}
// Then - Should find Kotlin summary
assertEquals(1, searchResults.size)
assertTrue(searchResults[0].messages.any { it.message.contains("Kotlin") })
}
}
@Test
fun testLongSummary_shouldTruncatePreview() {
// Given - Very long summary
val longSummary = "A".repeat(200) + " This is a very long summary that should be truncated in the preview"
// When - Create preview (max 30 chars)
val maxLength = 30
val preview = if (longSummary.length > maxLength) {
longSummary.take(maxLength).trim() + "..."
} else {
longSummary
}
// Then - Should be truncated
assertTrue(preview.length <= maxLength + 3)
assertTrue(preview.endsWith("..."))
}
@Test
fun testFileMetadata_shouldBePreserved() {
runBlocking {
// Given - Clear existing data
dataStoreManager.saveChatHistory(emptyList())
// File with metadata
val fileResult = FileParseResult.Success(
content = "Sample content for testing metadata preservation",
fileName = "important_document.pdf",
fileType = "PDF",
wordCount = 7
)
// When - Save chat with file metadata
val chatHistory = ChatHistory(
id = "chat_metadata",
categoryId = null,
categoryName = "Semua",
messages = listOf(
ChatMessage(
message = "📄 Upload file: ${fileResult.fileName}\n" +
"Tipe: ${fileResult.fileType}\n" +
"Jumlah kata: ${fileResult.wordCount}",
isUser = true
).toSerializable(),
ChatMessage(message = "Ringkasan telah dibuat.", isUser = false).toSerializable()
),
lastMessagePreview = "Ringkasan telah dibuat.",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.addChatHistory(chatHistory)
// Then - Metadata should be preserved
val savedHistories = dataStoreManager.chatHistoryFlow.first()
val userMessage = savedHistories[0].messages[0].message
assertTrue(userMessage.contains("important_document.pdf"))
assertTrue(userMessage.contains("PDF"))
assertTrue(userMessage.contains("7"))
}
}
}

View File

@ -1,433 +0,0 @@
package com.example.notesai
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.notesai.data.local.DataStoreManager
import com.example.notesai.data.model.Category
import com.example.notesai.data.model.Note
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
import java.util.UUID
/**
* Unit Test untuk Search Functionality
* Coverage:
* - TC-04: Search realtime menemukan keyword
*/
@RunWith(AndroidJUnit4::class)
class SearchFunctionalityTest {
private lateinit var context: Context
private lateinit var dataStore: DataStore<Preferences>
private lateinit var dataStoreManager: DataStoreManager
private lateinit var testScope: CoroutineScope
@Before
fun setup() {
context = ApplicationProvider.getApplicationContext()
testScope = CoroutineScope(SupervisorJob())
val testDataStoreName = "test_search_prefs_${UUID.randomUUID()}"
dataStore = PreferenceDataStoreFactory.create(
scope = testScope,
produceFile = { context.preferencesDataStoreFile(testDataStoreName) }
)
dataStoreManager = DataStoreManager(context)
}
@After
fun tearDown() {
testScope.cancel()
}
// ================== TC-04: SEARCH REALTIME ==================
@Test
fun testSearchNoteByTitle_shouldFindMatches() = runBlocking {
// Given - Create multiple notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Meeting Notes", content = "Discuss project", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Shopping List", content = "Buy groceries", isDeleted = false),
Note(id = "note_003", categoryId = "cat_001", title = "Project Ideas", content = "Brainstorm features", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for "Meeting" (simulating MainScreen search behavior)
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "Meeting"
val searchResults = savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should find 1 note
assertEquals(1, searchResults.size)
assertEquals("Meeting Notes", searchResults[0].title)
}
@Test
fun testSearchNoteByContent_shouldFindMatches() = runBlocking {
// Given - Notes with specific content
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Random Title", content = "This contains Kotlin code", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Another Note", content = "JavaScript examples here", isDeleted = false),
Note(id = "note_003", categoryId = "cat_001", title = "Third Note", content = "Python tutorials", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for "Kotlin"
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "Kotlin"
val searchResults = savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should find note with Kotlin in content
assertEquals(1, searchResults.size)
assertEquals("Random Title", searchResults[0].title)
assertTrue(searchResults[0].content.contains("Kotlin"))
}
@Test
fun testSearchCaseInsensitive_shouldFindMatches() = runBlocking {
// Given - Note with mixed case title
val note = Note(
id = "note_001",
categoryId = "cat_001",
title = "Android Development",
content = "Building mobile apps",
isDeleted = false
)
dataStoreManager.saveNotes(listOf(note))
// When - Search with different cases
val savedNotes = dataStoreManager.notesFlow.first()
val searchQueries = listOf("android", "ANDROID", "Android", "AnDrOiD")
searchQueries.forEach { searchQuery ->
val searchResults = savedNotes.filter { n ->
!n.isDeleted && !n.isArchived &&
(n.title.contains(searchQuery, ignoreCase = true) ||
n.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should find match regardless of case
assertEquals("Failed for query: $searchQuery", 1, searchResults.size)
}
}
@Test
fun testSearchPartialMatch_shouldFindResults() = runBlocking {
// Given - Notes with various titles
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Development Guide", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Developer Tools", isDeleted = false),
Note(id = "note_003", categoryId = "cat_001", title = "Design Patterns", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for partial word "Dev"
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "Dev"
val searchResults = savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should find 2 notes containing "Dev"
assertEquals(2, searchResults.size)
assertTrue(searchResults.any { it.title == "Development Guide" })
assertTrue(searchResults.any { it.title == "Developer Tools" })
}
@Test
fun testSearchEmptyQuery_shouldReturnAllNotes() = runBlocking {
// Given - Multiple notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Note 1", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Note 2", isDeleted = false),
Note(id = "note_003", categoryId = "cat_001", title = "Note 3", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search with empty query
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = ""
val searchResults = if (searchQuery.isEmpty()) {
savedNotes.filter { !it.isDeleted && !it.isArchived }
} else {
savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
}
// Then - Should return all active notes
assertEquals(3, searchResults.size)
}
@Test
fun testSearchNoMatches_shouldReturnEmpty() = runBlocking {
// Given - Notes that don't match search
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Note 1", content = "Content 1", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Note 2", content = "Content 2", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for non-existent keyword
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "NonExistentKeyword"
val searchResults = savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should return empty
assertEquals(0, searchResults.size)
}
@Test
fun testSearchExcludesDeletedNotes_shouldNotFindDeleted() = runBlocking {
// Given - Mix of active and deleted notes with same keyword
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Active Kotlin Note", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Deleted Kotlin Note", isDeleted = true),
Note(id = "note_003", categoryId = "cat_001", title = "Another Kotlin Note", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for "Kotlin"
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "Kotlin"
val searchResults = savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should only find 2 active notes
assertEquals(2, searchResults.size)
assertTrue(searchResults.all { !it.isDeleted })
assertFalse(searchResults.any { it.title == "Deleted Kotlin Note" })
}
@Test
fun testSearchExcludesArchivedNotes_shouldNotFindArchived() = runBlocking {
// Given - Mix of active and archived notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Active Project", isArchived = false),
Note(id = "note_002", categoryId = "cat_001", title = "Archived Project", isArchived = true),
Note(id = "note_003", categoryId = "cat_001", title = "Another Project", isArchived = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for "Project"
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "Project"
val searchResults = savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should only find 2 active notes
assertEquals(2, searchResults.size)
assertTrue(searchResults.all { !it.isArchived })
assertFalse(searchResults.any { it.title == "Archived Project" })
}
@Test
fun testSearchCategory_shouldFindByName() = runBlocking {
// Given - Multiple categories
val categories = listOf(
Category(id = "cat_001", name = "Work Projects", gradientStart = 0xFF000000, gradientEnd = 0xFF111111),
Category(id = "cat_002", name = "Personal Tasks", gradientStart = 0xFF222222, gradientEnd = 0xFF333333),
Category(id = "cat_003", name = "Ideas and Notes", gradientStart = 0xFF444444, gradientEnd = 0xFF555555)
)
dataStoreManager.saveCategories(categories)
// When - Search for "Work" (simulating MainScreen category search)
val savedCategories = dataStoreManager.categoriesFlow.first()
val searchQuery = "Work"
val searchResults = savedCategories.filter { category ->
!category.isDeleted &&
category.name.contains(searchQuery, ignoreCase = true)
}
// Then - Should find 1 category
assertEquals(1, searchResults.size)
assertEquals("Work Projects", searchResults[0].name)
}
@Test
fun testSearchCategoryPartialMatch_shouldFind() = runBlocking {
// Given - Categories with similar names
val categories = listOf(
Category(id = "cat_001", name = "Development", gradientStart = 0xFF000000, gradientEnd = 0xFF111111),
Category(id = "cat_002", name = "Developer Tools", gradientStart = 0xFF222222, gradientEnd = 0xFF333333),
Category(id = "cat_003", name = "Design", gradientStart = 0xFF444444, gradientEnd = 0xFF555555)
)
dataStoreManager.saveCategories(categories)
// When - Search for "Dev"
val savedCategories = dataStoreManager.categoriesFlow.first()
val searchQuery = "Dev"
val searchResults = savedCategories.filter { category ->
!category.isDeleted &&
category.name.contains(searchQuery, ignoreCase = true)
}
// Then - Should find 2 categories
assertEquals(2, searchResults.size)
assertTrue(searchResults.any { it.name == "Development" })
assertTrue(searchResults.any { it.name == "Developer Tools" })
}
@Test
fun testSearchMultipleKeywords_shouldFindAll() = runBlocking {
// Given - Notes with various content
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Kotlin Tutorial", content = "Learn Kotlin basics", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Java Guide", content = "Java programming", isDeleted = false),
Note(id = "note_003", categoryId = "cat_001", title = "Android Tips", content = "Kotlin for Android", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for "Kotlin"
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "Kotlin"
val searchResults = savedNotes.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should find 2 notes (title and content matches)
assertEquals(2, searchResults.size)
assertTrue(searchResults.any { it.title == "Kotlin Tutorial" })
assertTrue(searchResults.any { it.title == "Android Tips" })
}
@Test
fun testSearchRealtime_shouldUpdateImmediately() = runBlocking {
// Given - Initial set of notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "First Note", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Second Note", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for "First"
val savedNotes1 = dataStoreManager.notesFlow.first()
val searchQuery1 = "First"
val searchResults1 = savedNotes1.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery1, ignoreCase = true) ||
note.content.contains(searchQuery1, ignoreCase = true))
}
// Then - Should find 1 note
assertEquals(1, searchResults1.size)
// When - Change search query to "Second" (simulating real-time update)
val searchQuery2 = "Second"
val searchResults2 = savedNotes1.filter { note ->
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery2, ignoreCase = true) ||
note.content.contains(searchQuery2, ignoreCase = true))
}
// Then - Should immediately find different note
assertEquals(1, searchResults2.size)
assertEquals("Second Note", searchResults2[0].title)
}
@Test
fun testSearchWithSpecialCharacters_shouldHandle() = runBlocking {
// Given - Note with special characters
val note = Note(
id = "note_001",
categoryId = "cat_001",
title = "C++ Programming",
content = "Learn C++ basics & advanced topics",
isDeleted = false
)
dataStoreManager.saveNotes(listOf(note))
// When - Search for "C++"
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "C++"
val searchResults = savedNotes.filter { n ->
!n.isDeleted && !n.isArchived &&
(n.title.contains(searchQuery, ignoreCase = true) ||
n.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should find the note
assertEquals(1, searchResults.size)
assertEquals("C++ Programming", searchResults[0].title)
}
@Test
fun testSearchFilteredByCategory_shouldOnlySearchInCategory() = runBlocking {
// Given - Notes in different categories
val notes = listOf(
Note(id = "note_001", categoryId = "cat_work", title = "Work Meeting", isDeleted = false),
Note(id = "note_002", categoryId = "cat_personal", title = "Personal Meeting", isDeleted = false),
Note(id = "note_003", categoryId = "cat_work", title = "Work Report", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Search for "Meeting" in "cat_work" category only
val savedNotes = dataStoreManager.notesFlow.first()
val searchQuery = "Meeting"
val selectedCategoryId = "cat_work"
val searchResults = savedNotes.filter { note ->
note.categoryId == selectedCategoryId &&
!note.isDeleted && !note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Then - Should only find 1 note in cat_work
assertEquals(1, searchResults.size)
assertEquals("Work Meeting", searchResults[0].title)
assertEquals("cat_work", searchResults[0].categoryId)
}
}

View File

@ -1,323 +0,0 @@
package com.example.notesai
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.notesai.data.local.DataStoreManager
import com.example.notesai.data.model.Category
import com.example.notesai.data.model.Note
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
import java.util.UUID
/**
* Unit Test untuk Trash Functionality
* Coverage:
* - TC-03: Soft delete restore dari trash
*/
@RunWith(AndroidJUnit4::class)
class TrashFunctionalityTest {
private lateinit var context: Context
private lateinit var dataStore: DataStore<Preferences>
private lateinit var dataStoreManager: DataStoreManager
private lateinit var testScope: CoroutineScope
@Before
fun setup() {
context = ApplicationProvider.getApplicationContext()
testScope = CoroutineScope(SupervisorJob())
val testDataStoreName = "test_trash_prefs_${UUID.randomUUID()}"
dataStore = PreferenceDataStoreFactory.create(
scope = testScope,
produceFile = { context.preferencesDataStoreFile(testDataStoreName) }
)
dataStoreManager = DataStoreManager(context)
}
@After
fun tearDown() {
testScope.cancel()
}
// ================== TC-03: SOFT DELETE & RESTORE ==================
@Test
fun testSoftDeleteNote_shouldMarkAsDeleted() = runBlocking {
// Given - Create a note
val note = Note(
id = "note_001",
categoryId = "cat_001",
title = "Important Note",
content = "This is important content",
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.saveNotes(listOf(note))
// When - Soft delete the note
val deletedNote = note.copy(isDeleted = true)
dataStoreManager.saveNotes(listOf(deletedNote))
// Then - Note should be marked as deleted
val savedNotes = dataStoreManager.notesFlow.first()
assertEquals(1, savedNotes.size)
assertTrue(savedNotes[0].isDeleted)
assertEquals("Important Note", savedNotes[0].title)
}
@Test
fun testRestoreNoteFromTrash_shouldUnmarkDeleted() = runBlocking {
// Given - A deleted note
val deletedNote = Note(
id = "note_001",
categoryId = "cat_001",
title = "Deleted Note",
content = "This was deleted",
timestamp = System.currentTimeMillis(),
isDeleted = true
)
dataStoreManager.saveNotes(listOf(deletedNote))
// When - Restore the note
val restoredNote = deletedNote.copy(isDeleted = false)
dataStoreManager.saveNotes(listOf(restoredNote))
// Then - Note should be restored
val savedNotes = dataStoreManager.notesFlow.first()
assertEquals(1, savedNotes.size)
assertFalse(savedNotes[0].isDeleted)
assertEquals("Deleted Note", savedNotes[0].title)
}
@Test
fun testSoftDeleteCategory_shouldMarkAsDeleted() = runBlocking {
// Given - Create a category
val category = Category(
id = "cat_001",
name = "Work",
gradientStart = 0xFFE91E63,
gradientEnd = 0xFF9C27B0,
timestamp = System.currentTimeMillis(),
isDeleted = false
)
dataStoreManager.saveCategories(listOf(category))
// When - Soft delete the category
val deletedCategory = category.copy(isDeleted = true)
dataStoreManager.saveCategories(listOf(deletedCategory))
// Then - Category should be marked as deleted
val savedCategories = dataStoreManager.categoriesFlow.first()
assertEquals(1, savedCategories.size)
assertTrue(savedCategories[0].isDeleted)
assertEquals("Work", savedCategories[0].name)
}
@Test
fun testRestoreCategoryFromTrash_shouldUnmarkDeleted() = runBlocking {
// Given - A deleted category
val deletedCategory = Category(
id = "cat_001",
name = "Personal",
gradientStart = 0xFF2196F3,
gradientEnd = 0xFF03A9F4,
timestamp = System.currentTimeMillis(),
isDeleted = true
)
dataStoreManager.saveCategories(listOf(deletedCategory))
// When - Restore the category
val restoredCategory = deletedCategory.copy(isDeleted = false)
dataStoreManager.saveCategories(listOf(restoredCategory))
// Then - Category should be restored
val savedCategories = dataStoreManager.categoriesFlow.first()
assertEquals(1, savedCategories.size)
assertFalse(savedCategories[0].isDeleted)
assertEquals("Personal", savedCategories[0].name)
}
@Test
fun testFilterDeletedNotes_shouldOnlyShowDeleted() = runBlocking {
// Given - Mix of deleted and active notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Active 1", isDeleted = false),
Note(id = "note_002", categoryId = "cat_001", title = "Deleted 1", isDeleted = true),
Note(id = "note_003", categoryId = "cat_001", title = "Active 2", isDeleted = false),
Note(id = "note_004", categoryId = "cat_001", title = "Deleted 2", isDeleted = true),
Note(id = "note_005", categoryId = "cat_001", title = "Active 3", isDeleted = false)
)
dataStoreManager.saveNotes(notes)
// When - Filter only deleted notes (simulating TrashScreen behavior)
val savedNotes = dataStoreManager.notesFlow.first()
val deletedNotes = savedNotes.filter { it.isDeleted }
// Then - Should only have 2 deleted notes
assertEquals(2, deletedNotes.size)
assertTrue(deletedNotes.all { it.isDeleted })
assertEquals(setOf("Deleted 1", "Deleted 2"), deletedNotes.map { it.title }.toSet())
}
@Test
fun testFilterDeletedCategories_shouldOnlyShowDeleted() = runBlocking {
// Given - Mix of deleted and active categories
val categories = listOf(
Category(id = "cat_001", name = "Active Work", gradientStart = 0xFF000000, gradientEnd = 0xFF111111, isDeleted = false),
Category(id = "cat_002", name = "Deleted Personal", gradientStart = 0xFF222222, gradientEnd = 0xFF333333, isDeleted = true),
Category(id = "cat_003", name = "Active Ideas", gradientStart = 0xFF444444, gradientEnd = 0xFF555555, isDeleted = false),
Category(id = "cat_004", name = "Deleted Projects", gradientStart = 0xFF666666, gradientEnd = 0xFF777777, isDeleted = true)
)
dataStoreManager.saveCategories(categories)
// When - Filter only deleted categories
val savedCategories = dataStoreManager.categoriesFlow.first()
val deletedCategories = savedCategories.filter { it.isDeleted }
// Then - Should only have 2 deleted categories
assertEquals(2, deletedCategories.size)
assertTrue(deletedCategories.all { it.isDeleted })
assertEquals(setOf("Deleted Personal", "Deleted Projects"), deletedCategories.map { it.name }.toSet())
}
@Test
fun testPermanentDeleteNote_shouldRemoveCompletely() = runBlocking {
// Given - Two deleted notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Keep This", isDeleted = true),
Note(id = "note_002", categoryId = "cat_001", title = "Delete This", isDeleted = true)
)
dataStoreManager.saveNotes(notes)
// When - Permanently delete one note (remove from list)
val remainingNotes = notes.filter { it.id != "note_002" }
dataStoreManager.saveNotes(remainingNotes)
// Then - Should only have 1 note left
val savedNotes = dataStoreManager.notesFlow.first()
assertEquals(1, savedNotes.size)
assertEquals("Keep This", savedNotes[0].title)
}
@Test
fun testPermanentDeleteCategory_shouldRemoveCompletely() = runBlocking {
// Given - Two deleted categories
val categories = listOf(
Category(id = "cat_001", name = "Keep This", gradientStart = 0xFF000000, gradientEnd = 0xFF111111, isDeleted = true),
Category(id = "cat_002", name = "Delete This", gradientStart = 0xFF222222, gradientEnd = 0xFF333333, isDeleted = true)
)
dataStoreManager.saveCategories(categories)
// When - Permanently delete one category
val remainingCategories = categories.filter { it.id != "cat_002" }
dataStoreManager.saveCategories(remainingCategories)
// Then - Should only have 1 category left
val savedCategories = dataStoreManager.categoriesFlow.first()
assertEquals(1, savedCategories.size)
assertEquals("Keep This", savedCategories[0].name)
}
@Test
fun testSearchInTrash_shouldFindDeletedItems() = runBlocking {
// Given - Deleted notes with different content
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Meeting Minutes", content = "Discuss Q4 goals", isDeleted = true),
Note(id = "note_002", categoryId = "cat_001", title = "Shopping List", content = "Buy groceries", isDeleted = true),
Note(id = "note_003", categoryId = "cat_001", title = "Project Ideas", content = "Brainstorm features", isDeleted = true)
)
dataStoreManager.saveNotes(notes)
// When - Search for "Meeting" (simulating TrashScreen search)
val savedNotes = dataStoreManager.notesFlow.first()
val deletedNotes = savedNotes.filter { it.isDeleted }
val searchQuery = "Meeting"
val searchResults = deletedNotes.filter {
it.title.contains(searchQuery, ignoreCase = true) ||
it.content.contains(searchQuery, ignoreCase = true)
}
// Then - Should find 1 note
assertEquals(1, searchResults.size)
assertEquals("Meeting Minutes", searchResults[0].title)
}
@Test
fun testRestoreMultipleNotes_shouldRestoreAll() = runBlocking {
// Given - Multiple deleted notes
val notes = listOf(
Note(id = "note_001", categoryId = "cat_001", title = "Note 1", isDeleted = true),
Note(id = "note_002", categoryId = "cat_001", title = "Note 2", isDeleted = true),
Note(id = "note_003", categoryId = "cat_001", title = "Note 3", isDeleted = true)
)
dataStoreManager.saveNotes(notes)
// When - Restore all notes
val restoredNotes = notes.map { it.copy(isDeleted = false) }
dataStoreManager.saveNotes(restoredNotes)
// Then - All notes should be restored
val savedNotes = dataStoreManager.notesFlow.first()
assertEquals(3, savedNotes.size)
assertTrue(savedNotes.all { !it.isDeleted })
}
@Test
fun testDeletedNotePreservesAllData_shouldKeepContent() = runBlocking {
// Given - A note with all fields populated
val note = Note(
id = "note_001",
categoryId = "cat_001",
title = "Complete Note",
description = "This is a description",
content = "Full content here with details",
timestamp = System.currentTimeMillis(),
isPinned = true,
isArchived = false,
isDeleted = false
)
dataStoreManager.saveNotes(listOf(note))
// When - Soft delete
val deletedNote = note.copy(isDeleted = true)
dataStoreManager.saveNotes(listOf(deletedNote))
// Then - All data should be preserved
val savedNotes = dataStoreManager.notesFlow.first()
assertEquals(1, savedNotes.size)
with(savedNotes[0]) {
assertEquals("Complete Note", title)
assertEquals("This is a description", description)
assertEquals("Full content here with details", content)
assertTrue(isPinned)
assertFalse(isArchived)
assertTrue(isDeleted)
}
}
}

View File

@ -3,29 +3,19 @@
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<!-- Read files -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<!-- For Android 13+ -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<application
android:name=".NotesAIApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/iconapp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/iconapp"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NotesAI"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true"
android:theme="@style/Theme.NotesAI">
<intent-filter>

View File

@ -0,0 +1,5 @@
package com.example.notesai
object APIKey {
const val GEMINI_API_KEY = "AIzaSyBzC64RXsNtSERlts_FSd8HXKEpkLdT7-8"
}

View File

@ -0,0 +1,116 @@
@file:OptIn(kotlinx.serialization.InternalSerializationApi::class)
package com.example.notesai
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.Serializable
import java.io.IOException
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "notes_prefs")
@Serializable
data class SerializableCategory(
val id: String,
val name: String,
val gradientStart: Long,
val gradientEnd: Long,
val timestamp: Long
)
@Serializable
data class SerializableNote(
val id: String,
val categoryId: String,
val title: String,
val content: String,
val timestamp: Long,
val isArchived: Boolean,
val isDeleted: Boolean,
val isPinned: Boolean
)
class DataStoreManager(private val context: Context) {
companion object {
val CATEGORIES_KEY = stringPreferencesKey("categories")
val NOTES_KEY = stringPreferencesKey("notes")
}
private val json = Json {
ignoreUnknownKeys = true
encodeDefaults = true
}
val categoriesFlow: Flow<List<Category>> = context.dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(androidx.datastore.preferences.core.emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
val jsonString = preferences[CATEGORIES_KEY] ?: "[]"
try {
json.decodeFromString<List<SerializableCategory>>(jsonString).map {
Category(it.id, it.name, it.gradientStart, it.gradientEnd, it.timestamp)
}
} catch (e: Exception) {
emptyList()
}
}
val notesFlow: Flow<List<Note>> = context.dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(androidx.datastore.preferences.core.emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
val jsonString = preferences[NOTES_KEY] ?: "[]"
try {
json.decodeFromString<List<SerializableNote>>(jsonString).map {
Note(it.id, it.categoryId, it.title, it.content, it.timestamp, it.isArchived, it.isDeleted, it.isPinned)
}
} catch (e: Exception) {
emptyList()
}
}
suspend fun saveCategories(categories: List<Category>) {
try {
context.dataStore.edit { preferences ->
val serializable = categories.map {
SerializableCategory(it.id, it.name, it.gradientStart, it.gradientEnd, it.timestamp)
}
preferences[CATEGORIES_KEY] = json.encodeToString(serializable)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
suspend fun saveNotes(notes: List<Note>) {
try {
context.dataStore.edit { preferences ->
val serializable = notes.map {
SerializableNote(it.id, it.categoryId, it.title, it.content, it.timestamp, it.isArchived, it.isDeleted, it.isPinned)
}
preferences[NOTES_KEY] = json.encodeToString(serializable)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +0,0 @@
package com.example.notesai
import android.app.Application
import com.example.notesai.util.FileParser
class NotesAIApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize PDFBox
FileParser.initPDFBox(this)
}
}

View File

@ -1,5 +0,0 @@
package com.example.notesai.config
object APIKey {
const val GEMINI_API_KEY = "MY_GEMINI_KEY"
}

View File

@ -1,278 +0,0 @@
@file:OptIn(InternalSerializationApi::class)
package com.example.notesai.data.local
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.example.notesai.data.model.Note
import com.example.notesai.data.model.Category
import com.example.notesai.data.model.ChatHistory
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.Serializable
import java.io.IOException
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "notes_prefs")
@Serializable
data class SerializableCategory(
val id: String,
val name: String,
val gradientStart: Long,
val gradientEnd: Long,
val timestamp: Long,
val isDeleted: Boolean = false,
val isPinned: Boolean = false // NEW
)
@Serializable
data class SerializableNote(
val id: String,
val categoryId: String,
val title: String,
val description: String = "",
val content: String = "",
val timestamp: Long,
val isArchived: Boolean = false,
val isDeleted: Boolean = false,
val isPinned: Boolean = false
)
class DataStoreManager(private val context: Context) {
companion object {
val CATEGORIES_KEY = stringPreferencesKey("categories")
val NOTES_KEY = stringPreferencesKey("notes")
val CHAT_HISTORY_KEY = stringPreferencesKey("chat_history")
val THEME_KEY = stringPreferencesKey("theme") // "dark" or "light"
}
private val json = Json {
ignoreUnknownKeys = true
encodeDefaults = true
}
val categoriesFlow: Flow<List<Category>> = context.dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
val jsonString = preferences[CATEGORIES_KEY] ?: "[]"
try {
json.decodeFromString<List<SerializableCategory>>(jsonString).map {
Category(
id = it.id,
name = it.name,
gradientStart = it.gradientStart,
gradientEnd = it.gradientEnd,
timestamp = it.timestamp,
isDeleted = it.isDeleted,
isPinned = it.isPinned // NEW
)
}
} catch (e: Exception) {
e.printStackTrace()
emptyList()
}
}
val notesFlow: Flow<List<Note>> = context.dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
val jsonString = preferences[NOTES_KEY] ?: "[]"
try {
json.decodeFromString<List<SerializableNote>>(jsonString).map {
Note(
id = it.id,
categoryId = it.categoryId,
title = it.title,
description = it.description,
content = it.content,
timestamp = it.timestamp,
isPinned = it.isPinned,
isArchived = it.isArchived,
isDeleted = it.isDeleted
)
}
} catch (e: Exception) {
e.printStackTrace()
emptyList()
}
}
// Chat History Flow
val chatHistoryFlow: Flow<List<ChatHistory>> = context.dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
val jsonString = preferences[CHAT_HISTORY_KEY] ?: "[]"
try {
json.decodeFromString<List<ChatHistory>>(jsonString)
.filter { !it.isDeleted }
.sortedByDescending { it.timestamp }
} catch (e: Exception) {
e.printStackTrace()
emptyList()
}
}
suspend fun saveCategories(categories: List<Category>) {
try {
context.dataStore.edit { preferences ->
val serializable = categories.map {
SerializableCategory(
id = it.id,
name = it.name,
gradientStart = it.gradientStart,
gradientEnd = it.gradientEnd,
timestamp = it.timestamp,
isDeleted = it.isDeleted,
isPinned = it.isPinned // NEW
)
}
preferences[CATEGORIES_KEY] = json.encodeToString(serializable)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
suspend fun saveNotes(notes: List<Note>) {
try {
context.dataStore.edit { preferences ->
val serializable = notes.map {
SerializableNote(
id = it.id,
categoryId = it.categoryId,
title = it.title,
description = it.description,
content = it.content,
timestamp = it.timestamp,
isPinned = it.isPinned,
isArchived = it.isArchived,
isDeleted = it.isDeleted
)
}
preferences[NOTES_KEY] = json.encodeToString(serializable)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// Save Chat History
suspend fun saveChatHistory(chatHistoryList: List<ChatHistory>) {
try {
context.dataStore.edit { preferences ->
preferences[CHAT_HISTORY_KEY] = json.encodeToString(chatHistoryList)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// Add new chat history
suspend fun addChatHistory(chatHistory: ChatHistory) {
try {
context.dataStore.edit { preferences ->
val jsonString = preferences[CHAT_HISTORY_KEY] ?: "[]"
val currentList = json.decodeFromString<List<ChatHistory>>(jsonString).toMutableList()
// Check if already exists, update instead
val existingIndex = currentList.indexOfFirst { it.id == chatHistory.id }
if (existingIndex != -1) {
currentList[existingIndex] = chatHistory
} else {
currentList.add(0, chatHistory) // Add to beginning
}
preferences[CHAT_HISTORY_KEY] = json.encodeToString(currentList)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// Delete chat history (soft delete)
suspend fun deleteChatHistory(historyId: String) {
try {
context.dataStore.edit { preferences ->
val jsonString = preferences[CHAT_HISTORY_KEY] ?: "[]"
val currentList = json.decodeFromString<List<ChatHistory>>(jsonString).toMutableList()
val updatedList = currentList.map {
if (it.id == historyId) it.copy(isDeleted = true) else it
}
preferences[CHAT_HISTORY_KEY] = json.encodeToString(updatedList)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// NEW: Update chat history title
suspend fun updateChatHistoryTitle(historyId: String, newTitle: String) {
try {
context.dataStore.edit { preferences ->
val jsonString = preferences[CHAT_HISTORY_KEY] ?: "[]"
val currentList = json.decodeFromString<List<ChatHistory>>(jsonString).toMutableList()
val updatedList = currentList.map {
if (it.id == historyId) {
it.copy(customTitle = newTitle)
} else {
it
}
}
preferences[CHAT_HISTORY_KEY] = json.encodeToString(updatedList)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// Theme Preference Flow
val themeFlow: Flow<String> = context.dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
preferences[THEME_KEY] ?: "dark" // Default dark theme
}
// Save Theme Preference
suspend fun saveTheme(theme: String) {
try {
context.dataStore.edit { preferences ->
preferences[THEME_KEY] = theme
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}

View File

@ -1,15 +0,0 @@
package com.example.notesai.data.model
import kotlinx.serialization.Serializable
import java.util.UUID
@Serializable
data class Category(
val id: String = UUID.randomUUID().toString(),
val name: String,
val gradientStart: Long,
val gradientEnd: Long,
val timestamp: Long = System.currentTimeMillis(),
val isDeleted: Boolean = false,
val isPinned: Boolean = false // NEW: Tambahkan ini
)

View File

@ -1,40 +0,0 @@
package com.example.notesai.data.model
import kotlinx.serialization.Serializable
import java.util.UUID
@Serializable
data class ChatHistory(
val id: String = UUID.randomUUID().toString(),
val categoryId: String?, // null berarti "Semua Kategori"
val categoryName: String, // Untuk display
val messages: List<SerializableChatMessage>,
val lastMessagePreview: String, // Preview pesan terakhir
val customTitle: String? = null, // Custom title yang di-edit user (support markdown)
val timestamp: Long = System.currentTimeMillis(),
val isDeleted: Boolean = false
)
@Serializable
data class SerializableChatMessage(
val id: String,
val message: String,
val isUser: Boolean,
val timestamp: Long
)
// Extension function untuk convert ChatMessage ke SerializableChatMessage
fun ChatMessage.toSerializable() = SerializableChatMessage(
id = id,
message = message,
isUser = isUser,
timestamp = timestamp
)
// Extension function untuk convert SerializableChatMessage ke ChatMessage
fun SerializableChatMessage.toChatMessage() = ChatMessage(
id = id,
message = message,
isUser = isUser,
timestamp = timestamp
)

View File

@ -1,12 +0,0 @@
package com.example.notesai.data.model
import kotlinx.serialization.Serializable
import java.util.UUID
@Serializable
data class ChatMessage(
val id: String = UUID.randomUUID().toString(),
val message: String,
val isUser: Boolean,
val timestamp: Long = System.currentTimeMillis()
)

View File

@ -1,20 +0,0 @@
package com.example.notesai.data.model
import android.annotation.SuppressLint
//noinspection UnsafeOptInUsageError
import kotlinx.serialization.Serializable
import java.util.UUID
@SuppressLint("UnsafeOptInUsageError")
@Serializable
data class Note(
val id: String = UUID.randomUUID().toString(),
val categoryId: String,
val title: String,
val description: String = "", // Field baru untuk preview di NoteCard
val content: String = "", // Konten lengkap untuk EditableFullScreenNoteView
val timestamp: Long = System.currentTimeMillis(),
val isPinned: Boolean = false,
val isArchived: Boolean = false,
val isDeleted: Boolean = false
)

View File

@ -1,74 +0,0 @@
package com.example.notesai.data.model
import android.annotation.SuppressLint
import kotlinx.serialization.Serializable
@Serializable
data class SerializableCategory(
val id: String,
val name: String,
val gradientStart: Long,
val gradientEnd: Long,
val timestamp: Long,
val isDeleted: Boolean = false,
val isPinned: Boolean = false
)
@SuppressLint("UnsafeOptInUsageError")
@Serializable
data class SerializableNote(
val id: String,
val categoryId: String,
val title: String,
val description: String = "",
val content: String = "",
val timestamp: Long,
val isArchived: Boolean,
val isDeleted: Boolean,
val isPinned: Boolean
)
// Extension functions untuk konversi
fun Category.toSerializable() = SerializableCategory(
id = id,
name = name,
gradientStart = gradientStart,
gradientEnd = gradientEnd,
timestamp = timestamp,
isDeleted = isDeleted,
isPinned = isPinned
)
fun SerializableCategory.toCategory() = Category(
id = id,
name = name,
gradientStart = gradientStart,
gradientEnd = gradientEnd,
timestamp = timestamp,
isDeleted = isDeleted,
isPinned = isPinned
)
fun Note.toSerializable() = SerializableNote(
id = id,
categoryId = categoryId,
title = title,
description = description,
content = content,
timestamp = timestamp,
isArchived = isArchived,
isDeleted = isDeleted,
isPinned = isPinned
)
fun SerializableNote.toNote() = Note(
id = id,
categoryId = categoryId,
title = title,
description = description,
content = content,
timestamp = timestamp,
isArchived = isArchived,
isDeleted = isDeleted,
isPinned = isPinned
)

View File

@ -1,352 +0,0 @@
package com.example.notesai.presentation.components
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.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.notesai.util.Constants
import com.example.notesai.util.AppColors
@Composable
fun DrawerMenu(
currentScreen: String,
isDarkTheme: Boolean,
onDismiss: () -> Unit,
onItemClick: (String) -> Unit,
onThemeToggle: () -> Unit
) {
// Backdrop with blur effect
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black.copy(alpha = 0.5f))
.clickable(
onClick = onDismiss,
indication = null,
interactionSource = remember { MutableInteractionSource() }
)
) {
// Drawer Content
Surface(
modifier = Modifier
.fillMaxHeight()
.width(280.dp)
.align(Alignment.CenterStart)
.clickable(
onClick = {},
indication = null,
interactionSource = remember { MutableInteractionSource() }
),
color = AppColors.Surface,
shadowElevation = Constants.Elevation.ExtraLarge.dp
) {
Column(
modifier = Modifier.fillMaxSize()
) {
// Header - Minimalist
Box(
modifier = Modifier
.fillMaxWidth()
.background(
brush = Brush.verticalGradient(
colors = listOf(
AppColors.Primary.copy(alpha = 0.15f),
Color.Transparent
)
)
)
.padding(Constants.Spacing.ExtraLarge.dp)
) {
Column {
// App Icon with subtle background
Box(
modifier = Modifier
.size(56.dp)
.background(
color = AppColors.Primary.copy(alpha = 0.2f),
shape = RoundedCornerShape(Constants.Radius.Medium.dp)
),
contentAlignment = Alignment.Center
) {
Icon(
Icons.Default.Create,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(32.dp)
)
}
Spacer(modifier = Modifier.height(Constants.Spacing.Medium.dp))
Text(
"AI Notes",
style = MaterialTheme.typography.headlineMedium,
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold,
fontSize = 24.sp
)
Spacer(modifier = Modifier.height(Constants.Spacing.ExtraSmall.dp))
Text(
"Smart Note Taking",
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurfaceVariant,
fontSize = 14.sp
)
}
}
Spacer(modifier = Modifier.height(Constants.Spacing.Large.dp))
// Menu Items
DrawerMenuItem(
icon = if (currentScreen == "main") Icons.Filled.Home else Icons.Outlined.Home,
text = "Beranda",
isSelected = currentScreen == "main",
onClick = { onItemClick("main") }
)
DrawerMenuItem(
icon = if (currentScreen == "starred") Icons.Filled.Star else Icons.Outlined.StarBorder,
text = "Berbintang",
isSelected = currentScreen == "starred",
onClick = { onItemClick("starred") }
)
DrawerMenuItem(
icon = if (currentScreen == "archive") Icons.Filled.Archive else Icons.Outlined.Archive,
text = "Arsip",
isSelected = currentScreen == "archive",
onClick = { onItemClick("archive") }
)
DrawerMenuItem(
icon = if (currentScreen == "trash") Icons.Filled.Delete else Icons.Outlined.Delete,
text = "Sampah",
isSelected = currentScreen == "trash",
onClick = { onItemClick("trash") }
)
Spacer(modifier = Modifier.height(Constants.Spacing.Medium.dp))
HorizontalDivider(
color = AppColors.Divider,
modifier = Modifier.padding(horizontal = Constants.Spacing.Medium.dp)
)
Spacer(modifier = Modifier.height(Constants.Spacing.Medium.dp))
// Theme Toggle
ThemeToggleItem(
isDarkTheme = isDarkTheme,
onToggle = onThemeToggle
)
Spacer(modifier = Modifier.weight(1f))
// Footer - Version info
HorizontalDivider(
color = AppColors.Divider,
modifier = Modifier.padding(horizontal = Constants.Spacing.Medium.dp)
)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(Constants.Spacing.Medium.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
"Version 1.1.0",
style = MaterialTheme.typography.bodySmall,
color = AppColors.OnSurfaceTertiary,
fontSize = 12.sp
)
// Powered by badge
Surface(
color = AppColors.Primary.copy(alpha = 0.1f),
shape = RoundedCornerShape(Constants.Radius.Small.dp)
) {
Row(
modifier = Modifier.padding(horizontal = Constants.Spacing.Small.dp, vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
Icon(
Icons.Default.AutoAwesome,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(12.dp)
)
Text(
"Gemini AI",
color = AppColors.Primary,
fontSize = 11.sp,
fontWeight = FontWeight.Bold
)
}
}
}
}
}
}
}
@Composable
private fun ThemeToggleItem(
isDarkTheme: Boolean,
onToggle: () -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = Constants.Spacing.Medium.dp)
.clip(RoundedCornerShape(Constants.Radius.Medium.dp))
.clickable(onClick = onToggle)
.background(AppColors.SurfaceVariant)
.padding(horizontal = Constants.Spacing.Medium.dp, vertical = Constants.Spacing.Medium.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Constants.Spacing.Medium.dp)
) {
// Icon with background
Box(
modifier = Modifier
.size(40.dp)
.background(
color = AppColors.Primary.copy(alpha = 0.2f),
shape = CircleShape
),
contentAlignment = Alignment.Center
) {
Icon(
if (isDarkTheme) Icons.Default.DarkMode else Icons.Default.LightMode,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(20.dp)
)
}
// Text
Column {
Text(
"Tema Aplikasi",
style = MaterialTheme.typography.bodyLarge,
color = AppColors.OnSurface,
fontWeight = FontWeight.SemiBold,
fontSize = 15.sp
)
Text(
if (isDarkTheme) "Mode Gelap" else "Mode Terang",
style = MaterialTheme.typography.bodySmall,
color = AppColors.OnSurfaceTertiary,
fontSize = 12.sp
)
}
}
// Toggle Switch
Switch(
checked = isDarkTheme,
onCheckedChange = { onToggle() },
colors = SwitchDefaults.colors(
checkedThumbColor = Color.White,
checkedTrackColor = AppColors.Primary,
uncheckedThumbColor = Color.White,
uncheckedTrackColor = AppColors.Border
)
)
}
}
@Composable
private fun DrawerMenuItem(
icon: ImageVector,
text: String,
isSelected: Boolean,
onClick: () -> Unit
) {
// Scale animation
val scale by animateFloatAsState(
targetValue = if (isSelected) 1.02f else 1f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessMedium
),
label = "scale"
)
Row(
modifier = Modifier
.fillMaxWidth()
.scale(scale)
.clip(RoundedCornerShape(Constants.Radius.Medium.dp))
.clickable(onClick = onClick)
.background(
color = if (isSelected)
AppColors.Primary.copy(alpha = 0.1f)
else
Color.Transparent
)
.padding(horizontal = Constants.Spacing.Medium.dp, vertical = Constants.Spacing.Medium.dp),
verticalAlignment = Alignment.CenterVertically
) {
// Icon with background
Box(
modifier = Modifier
.size(40.dp)
.background(
color = if (isSelected)
AppColors.Primary.copy(alpha = 0.2f)
else
AppColors.SurfaceVariant,
shape = CircleShape
),
contentAlignment = Alignment.Center
) {
Icon(
icon,
contentDescription = null,
tint = if (isSelected) AppColors.Primary else AppColors.OnSurfaceVariant,
modifier = Modifier.size(20.dp)
)
}
Spacer(modifier = Modifier.width(Constants.Spacing.Medium.dp))
// Text
Text(
text,
style = MaterialTheme.typography.bodyLarge,
color = if (isSelected) AppColors.Primary else AppColors.OnSurface,
fontWeight = if (isSelected) FontWeight.SemiBold else FontWeight.Normal,
fontSize = 15.sp
)
}
}

View File

@ -1,56 +0,0 @@
package com.example.notesai.presentation.components
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
@Composable
fun EmptyState(
icon: ImageVector,
message: String,
subtitle: String
) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(32.dp)
) {
Icon(
icon,
contentDescription = null,
modifier = Modifier.size(80.dp),
tint = Color(0xFF475569)
)
Spacer(modifier = Modifier.height(16.dp))
Text(
message,
style = MaterialTheme.typography.titleLarge,
color = Color(0xFF94A3B8),
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(8.dp))
Text(
subtitle,
style = MaterialTheme.typography.bodyMedium,
color = Color(0xFF64748B)
)
}
}
}

View File

@ -1,51 +0,0 @@
package com.example.notesai.presentation.components
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
@Composable
fun MenuItem(
icon: ImageVector,
text: String,
isSelected: Boolean,
onClick: () -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onClick)
.background(
if (isSelected) Color(0xFF334155) else Color.Transparent
)
.padding(horizontal = 20.dp, vertical = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
icon,
contentDescription = null,
tint = if (isSelected) Color(0xFFA855F7) else Color(0xFF94A3B8)
)
Spacer(modifier = Modifier.width(16.dp))
Text(
text,
style = MaterialTheme.typography.bodyLarge,
color = if (isSelected) Color.White else Color(0xFF94A3B8),
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal
)
}
}

View File

@ -1,159 +0,0 @@
package com.example.notesai.presentation.components
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.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.outlined.AutoAwesome
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.StarBorder
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.draw.shadow
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 com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
@Composable
fun ModernBottomBar(
currentScreen: String,
onHomeClick: () -> Unit,
onAIClick: () -> Unit
) {
// Floating Bottom Bar with Glassmorphism
Box(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Surface(
modifier = Modifier
.fillMaxWidth()
.shadow(
elevation = Constants.Elevation.Large.dp,
shape = RoundedCornerShape(Constants.Radius.ExtraLarge.dp)
),
color = AppColors.SurfaceElevated,
shape = RoundedCornerShape(Constants.Radius.ExtraLarge.dp)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp, horizontal = 24.dp),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
// Home Button
BottomBarItem(
selected = currentScreen == "main",
onClick = onHomeClick,
icon = if (currentScreen == "main") Icons.Filled.Home else Icons.Outlined.Home,
label = "Beranda"
)
// AI Button
BottomBarItem(
selected = currentScreen == "ai",
onClick = onAIClick,
icon = if (currentScreen == "ai") Icons.Filled.AutoAwesome else Icons.Outlined.AutoAwesome,
label = "AI Helper"
)
}
}
}
}
@Composable
private fun BottomBarItem(
selected: Boolean,
onClick: () -> Unit,
icon: androidx.compose.ui.graphics.vector.ImageVector,
label: String
) {
// Scale animation
val scale by animateFloatAsState(
targetValue = if (selected) 1.1f else 1f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
),
label = "scale"
)
// Color animation
val iconColor by animateColorAsState(
targetValue = if (selected) AppColors.Primary else AppColors.OnSurfaceVariant,
animationSpec = tween(Constants.ANIMATION_DURATION_MEDIUM),
label = "color"
)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.clip(RoundedCornerShape(12.dp))
.clickable(
onClick = onClick,
indication = null,
interactionSource = remember { MutableInteractionSource() }
)
.padding(horizontal = 24.dp, vertical = 8.dp)
) {
// Icon with background indicator
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(48.dp)
.scale(scale)
) {
// Background indicator
if (selected) {
Box(
modifier = Modifier
.size(40.dp)
.background(
color = AppColors.Primary.copy(alpha = 0.15f),
shape = CircleShape
)
)
}
Icon(
icon,
contentDescription = label,
tint = iconColor,
modifier = Modifier.size(24.dp)
)
}
// Label with fade animation
AnimatedVisibility(
visible = selected,
enter = fadeIn() + expandVertically(),
exit = fadeOut() + shrinkVertically()
) {
Spacer(modifier = Modifier.height(4.dp))
Text(
label,
color = AppColors.Primary,
style = MaterialTheme.typography.bodySmall,
fontWeight = FontWeight.Bold,
fontSize = 12.sp
)
}
}
}

View File

@ -1,179 +0,0 @@
package com.example.notesai.presentation.components
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
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 com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ModernTopBar(
title: String,
showBackButton: Boolean,
onBackClick: () -> Unit,
onMenuClick: () -> Unit,
onSearchClick: () -> Unit,
searchQuery: String,
onSearchQueryChange: (String) -> Unit,
showSearch: Boolean
) {
// Floating Top Bar with same style as Bottom Bar
Box(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
) {
Surface(
modifier = Modifier
.fillMaxWidth()
.shadow(
elevation = Constants.Elevation.Large.dp,
shape = RoundedCornerShape(Constants.Radius.ExtraLarge.dp)
),
color = AppColors.SurfaceElevated,
shape = RoundedCornerShape(Constants.Radius.ExtraLarge.dp)
) {
// Smooth transition for search bar
AnimatedContent(
targetState = showSearch,
transitionSpec = {
fadeIn(animationSpec = tween(Constants.ANIMATION_DURATION_MEDIUM)) togetherWith
fadeOut(animationSpec = tween(Constants.ANIMATION_DURATION_MEDIUM))
},
label = "topbar"
) { isSearching ->
if (isSearching) {
// Search Mode
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
// Search TextField
OutlinedTextField(
value = searchQuery,
onValueChange = onSearchQueryChange,
placeholder = {
Text(
"Cari...",
color = AppColors.OnSurfaceVariant,
fontSize = 15.sp
)
},
colors = OutlinedTextFieldDefaults.colors(
focusedContainerColor = AppColors.SurfaceVariant,
unfocusedContainerColor = AppColors.SurfaceVariant,
focusedTextColor = AppColors.OnBackground,
unfocusedTextColor = AppColors.OnSurface,
cursorColor = AppColors.Primary,
focusedBorderColor = AppColors.Primary,
unfocusedBorderColor = Color.Transparent
),
modifier = Modifier
.weight(1f)
.heightIn(min = 48.dp),
shape = RoundedCornerShape(Constants.Radius.Large.dp),
singleLine = true,
textStyle = LocalTextStyle.current.copy(fontSize = 15.sp)
)
// Close Search Button
IconButton(
onClick = {
onSearchQueryChange("")
onSearchClick()
},
modifier = Modifier
.size(40.dp)
.clip(CircleShape)
.background(AppColors.SurfaceVariant)
) {
Icon(
Icons.Default.Close,
contentDescription = "Close Search",
tint = AppColors.OnSurfaceVariant,
modifier = Modifier.size(20.dp)
)
}
}
} else {
// Normal Mode
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
// Back/Menu Button
IconButton(
onClick = if (showBackButton) onBackClick else onMenuClick,
modifier = Modifier
.size(40.dp)
.clip(CircleShape)
.background(
if (showBackButton) AppColors.SurfaceVariant
else AppColors.Primary.copy(alpha = 0.1f)
)
) {
Icon(
if (showBackButton) Icons.AutoMirrored.Filled.ArrowBack else Icons.Default.Menu,
contentDescription = if (showBackButton) "Back" else "Menu",
tint = if (showBackButton) AppColors.OnSurface else AppColors.Primary,
modifier = Modifier.size(20.dp)
)
}
// Title
Text(
title,
fontWeight = FontWeight.Bold,
fontSize = 18.sp,
color = AppColors.OnBackground,
modifier = Modifier
.weight(1f)
.padding(horizontal = 12.dp)
)
// Search Button
IconButton(
onClick = onSearchClick,
modifier = Modifier
.size(40.dp)
.clip(CircleShape)
.background(AppColors.SurfaceVariant)
) {
Icon(
Icons.Default.Search,
contentDescription = "Search",
tint = AppColors.OnSurfaceVariant,
modifier = Modifier.size(20.dp)
)
}
}
}
}
}
}
}

View File

@ -1,191 +0,0 @@
package com.example.notesai.presentation.dialogs
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
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 com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
@Composable
fun CategoryDialog(
onDismiss: () -> Unit,
onSave: (String, Long, Long) -> Unit
) {
var name by remember { mutableStateOf("") }
var selectedGradient by remember { mutableStateOf(0) }
AlertDialog(
onDismissRequest = onDismiss,
containerColor = AppColors.Surface,
shape = RoundedCornerShape(Constants.Radius.Large.dp),
title = {
Text(
"Kategori Baru",
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold,
fontSize = 20.sp
)
},
text = {
Column(
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
// Name Input
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = {
Text(
"Nama Kategori",
color = AppColors.OnSurfaceVariant
)
},
placeholder = {
Text(
"Contoh: Pekerjaan, Pribadi...",
color = AppColors.OnSurfaceTertiary,
fontSize = 14.sp
)
},
modifier = Modifier.fillMaxWidth(),
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = AppColors.OnBackground,
unfocusedTextColor = AppColors.OnSurface,
focusedContainerColor = AppColors.SurfaceVariant,
unfocusedContainerColor = AppColors.SurfaceVariant,
cursorColor = AppColors.Primary,
focusedBorderColor = AppColors.Primary,
unfocusedBorderColor = Color.Transparent
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
singleLine = true
)
Spacer(modifier = Modifier.height(8.dp))
// Color picker title
Text(
"Pilih Warna:",
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurface,
fontWeight = FontWeight.SemiBold,
fontSize = 14.sp
)
Spacer(modifier = Modifier.height(8.dp))
// Color Grid - 2 rows of 4 colors
Constants.CategoryColors.chunked(4).forEach { row ->
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
row.forEachIndexed { _, gradient ->
val globalIndex = Constants.CategoryColors.indexOf(gradient)
val isSelected = selectedGradient == globalIndex
Box(
modifier = Modifier
.weight(1f)
.aspectRatio(1f)
.clip(RoundedCornerShape(Constants.Radius.Medium.dp))
.background(
brush = Brush.linearGradient(
colors = listOf(
Color(gradient.first),
Color(gradient.second)
)
)
)
.clickable { selectedGradient = globalIndex },
contentAlignment = Alignment.Center
) {
// Checkmark with animation
androidx.compose.animation.AnimatedVisibility(
visible = isSelected,
enter = scaleIn(
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessMedium
)
) + fadeIn(),
exit = scaleOut(
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessMedium
)
) + fadeOut()
) {
Icon(
Icons.Default.Check,
contentDescription = "Selected",
tint = Color.White,
modifier = Modifier.size(28.dp)
)
}
}
}
}
Spacer(modifier = Modifier.height(12.dp))
}
}
},
confirmButton = {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
// Cancel button
TextButton(
onClick = onDismiss,
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
modifier = Modifier.height(48.dp)
) {
Text(
"Batal",
color = AppColors.OnSurfaceVariant,
fontSize = 15.sp
)
}
// Save button
Button(
onClick = {
if (name.isNotBlank()) {
val gradient = Constants.CategoryColors[selectedGradient]
onSave(name, gradient.first, gradient.second)
}
},
enabled = name.isNotBlank(),
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Primary,
disabledContainerColor = AppColors.Primary.copy(alpha = 0.5f)
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
modifier = Modifier.height(48.dp)
) {
Text(
"Buat",
color = Color.White,
fontWeight = FontWeight.Bold,
fontSize = 15.sp
)
}
}
}
)
}

View File

@ -1,213 +0,0 @@
package com.example.notesai.presentation.dialogs
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.*
import androidx.compose.runtime.*
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 com.example.notesai.data.model.Note
import com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
@Composable
fun NoteDialog(
categoryId: String, // Parameter untuk kategori ID
note: Note? = null, // Null jika buat baru, isi jika edit
onDismiss: () -> Unit,
onSave: (String, String) -> Unit,
onDelete: (() -> Unit)? = null
) {
var title by remember { mutableStateOf(note?.title ?: "") }
var description by remember { mutableStateOf(note?.description ?: "") }
var showDeleteConfirm by remember { mutableStateOf(false) }
// Delete confirmation dialog
if (showDeleteConfirm) {
AlertDialog(
onDismissRequest = { showDeleteConfirm = false },
containerColor = AppColors.Surface,
shape = RoundedCornerShape(Constants.Radius.Large.dp),
title = {
Text(
"Hapus Catatan?",
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold
)
},
text = {
Text(
"Catatan ini akan dipindahkan ke sampah.",
color = AppColors.OnSurfaceVariant
)
},
confirmButton = {
Button(
onClick = {
onDelete?.invoke()
showDeleteConfirm = false
},
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Error
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp)
) {
Text("Hapus", color = Color.White, fontWeight = FontWeight.Bold)
}
},
dismissButton = {
TextButton(
onClick = { showDeleteConfirm = false },
shape = RoundedCornerShape(Constants.Radius.Medium.dp)
) {
Text("Batal", color = AppColors.OnSurfaceVariant)
}
}
)
}
AlertDialog(
onDismissRequest = onDismiss,
containerColor = AppColors.Surface,
shape = RoundedCornerShape(Constants.Radius.Large.dp),
title = {
Text(
if (note == null) "Catatan Baru" else "Edit Catatan",
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold,
fontSize = 20.sp
)
},
text = {
Column(
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
// Title Input
OutlinedTextField(
value = title,
onValueChange = { title = it },
label = {
Text(
"Judul",
color = AppColors.OnSurfaceVariant
)
},
placeholder = {
Text(
"Masukkan judul catatan",
color = AppColors.OnSurfaceTertiary,
fontSize = 14.sp
)
},
modifier = Modifier.fillMaxWidth(),
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = AppColors.OnBackground,
unfocusedTextColor = AppColors.OnSurface,
focusedContainerColor = AppColors.SurfaceVariant,
unfocusedContainerColor = AppColors.SurfaceVariant,
cursorColor = AppColors.Primary,
focusedBorderColor = AppColors.Primary,
unfocusedBorderColor = Color.Transparent
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
singleLine = true
)
// Description Input
OutlinedTextField(
value = description,
onValueChange = { description = it },
label = {
Text(
"Deskripsi",
color = AppColors.OnSurfaceVariant
)
},
placeholder = {
Text(
"Tambahkan deskripsi singkat...",
color = AppColors.OnSurfaceTertiary,
fontSize = 14.sp
)
},
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 120.dp, max = 200.dp),
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = AppColors.OnBackground,
unfocusedTextColor = AppColors.OnSurface,
focusedContainerColor = AppColors.SurfaceVariant,
unfocusedContainerColor = AppColors.SurfaceVariant,
cursorColor = AppColors.Primary,
focusedBorderColor = AppColors.Primary,
unfocusedBorderColor = Color.Transparent
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
maxLines = 8
)
}
},
confirmButton = {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
// Delete button (if editing)
if (onDelete != null) {
IconButton(
onClick = { showDeleteConfirm = true },
modifier = Modifier.size(48.dp)
) {
Icon(
Icons.Default.Delete,
contentDescription = "Hapus",
tint = AppColors.Error
)
}
}
Spacer(modifier = Modifier.weight(1f))
// Cancel button
TextButton(
onClick = onDismiss,
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
modifier = Modifier.height(48.dp)
) {
Text(
"Batal",
color = AppColors.OnSurfaceVariant,
fontSize = 15.sp
)
}
// Save button
Button(
onClick = {
if (title.isNotBlank()) {
onSave(title, description)
}
},
enabled = title.isNotBlank(),
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Primary,
disabledContainerColor = AppColors.Primary.copy(alpha = 0.5f)
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
modifier = Modifier.height(48.dp)
) {
Text(
"Simpan",
color = Color.White,
fontWeight = FontWeight.Bold,
fontSize = 15.sp
)
}
}
}
)
}

View File

@ -1,689 +0,0 @@
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
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.AnnotatedString
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.*
import com.example.notesai.util.Constants
import com.google.ai.client.generativeai.GenerativeModel
import com.google.ai.client.generativeai.type.generationConfig
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.*
import com.example.notesai.presentation.screens.ai.components.*
import com.example.notesai.util.AppColors
import com.example.notesai.util.FileParseResult
private const val MAX_CHAT_TITLE_LENGTH = 30
private fun String.toSafeChatPreview(maxLength: Int = MAX_CHAT_TITLE_LENGTH): String {
return if (this.length > maxLength) {
this.take(maxLength).trim() + "..."
} else {
this.trim()
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AIHelperScreen(
categories: List<Category>,
notes: List<Note>,
onShowDrawer: () -> Unit = {}
) {
val context = LocalContext.current
val dataStoreManager = remember { DataStoreManager(context) }
var prompt by remember { mutableStateOf("") }
var isLoading by remember { mutableStateOf(false) }
var selectedCategory by remember { mutableStateOf<Category?>(null) }
var errorMessage by remember { mutableStateOf("") }
var chatMessages by remember { mutableStateOf(listOf<ChatMessage>()) }
var showCopiedMessage by remember { mutableStateOf(false) }
var copiedMessageId by remember { mutableStateOf("") }
var showHistoryDrawer by remember { mutableStateOf(false) }
var currentChatId by remember { mutableStateOf<String?>(null) }
// File Upload States
var uploadedFile by remember { mutableStateOf<FileParseResult.Success?>(null) }
var isGeneratingSummary by remember { mutableStateOf(false) }
val scope = rememberCoroutineScope()
val clipboardManager = LocalClipboardManager.current
val scrollState = rememberScrollState()
// Load chat histories
val chatHistories by dataStoreManager.chatHistoryFlow.collectAsState(initial = emptyList())
// Inisialisasi Gemini Model
val generativeModel = remember {
GenerativeModel(
modelName = "gemini-2.5-flash",
apiKey = APIKey.GEMINI_API_KEY,
generationConfig = generationConfig {
temperature = 0.8f
topK = 40
topP = 0.95f
maxOutputTokens = 4096
candidateCount = 1
}
)
}
// Auto scroll ke bawah saat ada pesan baru
LaunchedEffect(chatMessages.size) {
if (chatMessages.isNotEmpty()) {
delay(100)
scrollState.animateScrollTo(scrollState.maxValue)
}
}
// Function to save chat history
fun saveChatHistory() {
if (chatMessages.isNotEmpty()) {
scope.launch {
val lastMessage = chatMessages.lastOrNull()?.message ?: ""
val preview = lastMessage.toSafeChatPreview()
val chatHistory = ChatHistory(
id = currentChatId ?: UUID.randomUUID().toString(),
categoryId = selectedCategory?.id,
categoryName = selectedCategory?.name ?: "Semua Kategori",
messages = chatMessages.map { it.toSerializable() },
lastMessagePreview = preview,
customTitle = null,
timestamp = System.currentTimeMillis()
)
dataStoreManager.addChatHistory(chatHistory)
currentChatId = chatHistory.id
}
}
}
// Function to load chat history
fun loadChatHistory(history: ChatHistory) {
chatMessages = history.messages.map { it.toChatMessage() }
currentChatId = history.id
selectedCategory = categories.find { it.id == history.categoryId }
showHistoryDrawer = false
}
// Function to start new chat
fun startNewChat() {
chatMessages = emptyList()
currentChatId = null
errorMessage = ""
showHistoryDrawer = false
uploadedFile = null
isGeneratingSummary = false
}
Box(
modifier = Modifier.fillMaxSize()
) {
// MAIN CONTENT - Layer 1 (paling bawah)
Column(
modifier = Modifier
.fillMaxSize()
.background(AppColors.Background)
) {
// UPDATED: Floating Top Bar
Box(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
) {
Surface(
color = AppColors.SurfaceElevated,
shape = RoundedCornerShape(Constants.Radius.ExtraLarge.dp),
shadowElevation = Constants.Elevation.Large.dp
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 8.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
// History Drawer Button
IconButton(
onClick = {
onShowDrawer() // Panggil callback ke parent
},
modifier = Modifier
.size(40.dp)
.background(
AppColors.Primary.copy(alpha = 0.1f),
CircleShape
)
) {
Icon(
Icons.Default.Menu,
contentDescription = "Menu",
tint = AppColors.Primary,
modifier = Modifier.size(20.dp)
)
}
// Category Badge
Surface(
color = AppColors.Primary.copy(alpha = 0.1f),
shape = RoundedCornerShape(Constants.Radius.Medium.dp)
) {
Row(
modifier = Modifier.padding(
horizontal = Constants.Spacing.Medium.dp,
vertical = Constants.Spacing.Small.dp
),
horizontalArrangement = Arrangement.spacedBy(6.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.Folder,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(16.dp)
)
Text(
selectedCategory?.name ?: "Semua Kategori",
color = AppColors.Primary,
fontSize = 13.sp,
fontWeight = FontWeight.SemiBold
)
}
}
// New Chat Button
if (chatMessages.isNotEmpty()) {
Button(
onClick = { startNewChat() },
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Primary
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
contentPadding = PaddingValues(
horizontal = Constants.Spacing.Medium.dp,
vertical = Constants.Spacing.Small.dp
)
) {
Icon(
Icons.Default.Add,
contentDescription = null,
modifier = Modifier.size(18.dp)
)
Spacer(modifier = Modifier.width(6.dp))
Text(
"Baru",
fontSize = 14.sp,
fontWeight = FontWeight.SemiBold
)
}
}
}
}
}
// Chat Area
Box(
modifier = Modifier
.weight(1f)
.fillMaxWidth()
) {
if (chatMessages.isEmpty()) {
// Welcome State - Optimized Layout
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 24.dp, vertical = 16.dp)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Spacer(modifier = Modifier.weight(0.5f))
Box(
modifier = Modifier
.size(64.dp)
.background(
color = AppColors.Primary.copy(alpha = 0.1f),
shape = CircleShape
),
contentAlignment = Alignment.Center
) {
Icon(
Icons.Default.AutoAwesome,
contentDescription = null,
modifier = Modifier.size(32.dp),
tint = AppColors.Primary
)
}
Text(
"AI Assistant",
style = MaterialTheme.typography.headlineMedium,
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold,
fontSize = 24.sp
)
Text(
"Tanyakan apa saja tentang catatan Anda",
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurfaceVariant,
textAlign = TextAlign.Center,
fontSize = 14.sp
)
Spacer(modifier = Modifier.height(8.dp))
// Suggestion Chips - Lebih besar
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(10.dp),
modifier = Modifier.fillMaxWidth()
) {
Text(
"Contoh pertanyaan:",
style = MaterialTheme.typography.labelMedium,
color = AppColors.OnSurfaceTertiary,
fontSize = 13.sp
)
SuggestionChip("Analisis catatan saya") { prompt = it }
SuggestionChip("Buat ringkasan") { prompt = it }
SuggestionChip("Berikan saran organisasi") { prompt = it }
}
Spacer(modifier = Modifier.height(8.dp))
// File Upload Button - PENTING: Jangan dihapus!
FileUploadButton(
onFileSelected = { fileResult ->
uploadedFile = fileResult
// Auto-generate summary
scope.launch {
isGeneratingSummary = true
try {
val summaryPrompt = """
Buatkan ringkasan dari dokumen berikut dalam bahasa Indonesia:
Judul File: ${fileResult.fileName}
Tipe: ${fileResult.fileType}
Jumlah Kata: ${fileResult.wordCount}
Konten:
${fileResult.content}
Buat ringkasan yang:
1. Mencakup poin-poin utama
2. Terstruktur dengan baik (gunakan markdown)
3. Mudah dipahami
4. Maksimal 300 kata
""".trimIndent()
// Add user message
chatMessages = chatMessages + ChatMessage(
message = "📄 Upload file: ${fileResult.fileName}\n\nMohon buatkan ringkasan dari file ini.",
isUser = true
)
// Scroll to bottom to show loading
delay(100)
scrollState.animateScrollTo(scrollState.maxValue)
// Generate summary dengan Gemini
val response =
generativeModel.generateContent(summaryPrompt)
val summary = response.text ?: "Gagal membuat ringkasan"
// Add AI response
chatMessages = chatMessages + ChatMessage(
message = summary,
isUser = false
)
saveChatHistory()
} catch (e: Exception) {
errorMessage = "⚠️ Gagal membuat ringkasan: ${e.message}"
} finally {
isGeneratingSummary = false
uploadedFile = null
}
}
},
onError = { error ->
errorMessage = error
},
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.weight(0.5f))
}
} else {
// Chat Messages - UPDATED: Bottom padding dari 100dp ke 120dp
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 120.dp)
) {
chatMessages.forEach { message ->
ChatBubble(
message = message,
onCopy = { textToCopy ->
clipboardManager.setText(AnnotatedString(textToCopy))
copiedMessageId = message.id
showCopiedMessage = true
scope.launch {
delay(2000)
showCopiedMessage = false
}
},
showCopied = showCopiedMessage && copiedMessageId == message.id
)
Spacer(modifier = Modifier.height(12.dp))
}
// Loading Indicator
if (isLoading || isGeneratingSummary) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp),
horizontalArrangement = Arrangement.Start
) {
Surface(
color = AppColors.SurfaceVariant,
shape = RoundedCornerShape(16.dp)
) {
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = if (isGeneratingSummary) AppColors.Secondary else AppColors.Primary,
strokeWidth = 2.dp
)
Text(
if (isGeneratingSummary) "Membuat ringkasan..." else "AI sedang berpikir...",
color = AppColors.OnSurfaceVariant,
style = MaterialTheme.typography.bodyMedium
)
}
}
}
}
// Error Message
if (errorMessage.isNotEmpty()) {
Surface(
modifier = Modifier.fillMaxWidth(),
color = AppColors.Error.copy(alpha = 0.1f),
shape = RoundedCornerShape(12.dp)
) {
Row(
modifier = Modifier.padding(12.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Icon(
Icons.Default.Warning,
contentDescription = null,
tint = AppColors.Error,
modifier = Modifier.size(20.dp)
)
Text(
errorMessage,
color = AppColors.Error,
style = MaterialTheme.typography.bodySmall
)
}
}
}
}
}
}
// Input Area - Layer 2 (di atas chat, tapi di bawah drawer)
Surface(
color = AppColors.Surface,
shadowElevation = 8.dp,
shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
// Upload File Button (di atas input text)
if (chatMessages.isNotEmpty() && !isGeneratingSummary && !isLoading) {
FileUploadButton(
onFileSelected = { fileResult ->
uploadedFile = fileResult
scope.launch {
isGeneratingSummary = true
try {
val summaryPrompt = """
Buatkan ringkasan dari dokumen berikut dalam bahasa Indonesia:
Judul File: ${fileResult.fileName}
Tipe: ${fileResult.fileType}
Jumlah Kata: ${fileResult.wordCount}
Konten:
${fileResult.content}
Buat ringkasan yang:
1. Mencakup poin-poin utama
2. Terstruktur dengan baik (gunakan markdown)
3. Mudah dipahami
4. Maksimal 300 kata
""".trimIndent()
chatMessages = chatMessages + ChatMessage(
message = "📄 Upload file: ${fileResult.fileName}\n\nMohon buatkan ringkasan dari file ini.",
isUser = true
)
delay(100)
scrollState.animateScrollTo(scrollState.maxValue)
val response =
generativeModel.generateContent(summaryPrompt)
val summary = response.text ?: "Gagal membuat ringkasan"
chatMessages = chatMessages + ChatMessage(
message = summary,
isUser = false
)
saveChatHistory()
} catch (e: Exception) {
errorMessage = "⚠️ Gagal membuat ringkasan: ${e.message}"
} finally {
isGeneratingSummary = false
uploadedFile = null
}
}
},
onError = { error ->
errorMessage = error
},
modifier = Modifier.fillMaxWidth()
)
}
// Text Input & Send Button
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.Bottom,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
OutlinedTextField(
value = prompt,
onValueChange = { prompt = it },
placeholder = {
Text(
"Ketik pesan...",
color = AppColors.OnSurfaceTertiary
)
},
modifier = Modifier
.weight(1f)
.heightIn(min = 48.dp, max = 120.dp),
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = AppColors.OnBackground,
unfocusedTextColor = AppColors.OnSurface,
focusedContainerColor = AppColors.SurfaceVariant,
unfocusedContainerColor = AppColors.SurfaceVariant,
cursorColor = AppColors.Primary,
focusedBorderColor = AppColors.Primary,
unfocusedBorderColor = Color.Transparent
),
shape = RoundedCornerShape(24.dp),
maxLines = 4
)
// Send Button
FloatingActionButton(
onClick = {
if (prompt.isNotBlank() && !isLoading) {
scope.launch {
chatMessages = chatMessages + ChatMessage(
message = prompt,
isUser = true
)
val userPrompt = prompt
prompt = ""
isLoading = true
errorMessage = ""
try {
val filteredNotes = if (selectedCategory != null) {
notes.filter { it.categoryId == selectedCategory!!.id && !it.isArchived }
} else {
notes.filter { !it.isArchived }
}
val notesContext = buildString {
appendLine("Data catatan pengguna:")
appendLine("Total catatan: ${filteredNotes.size}")
appendLine("Kategori: ${selectedCategory?.name ?: "Semua"}")
appendLine()
appendLine("Daftar catatan:")
filteredNotes.take(10).forEach { note ->
appendLine("- Judul: ${note.title}")
appendLine(" Isi: ${note.content.take(100)}")
appendLine()
}
}
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"
chatMessages = chatMessages + ChatMessage(
message = response,
isUser = false
)
saveChatHistory()
} catch (e: Exception) {
errorMessage = when {
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 ->
"⚠️ Model AI tidak ditemukan. Silakan hubungi developer."
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 ->
"⚠️ Koneksi timeout. Periksa koneksi internet Anda."
e.message?.contains(
"network",
ignoreCase = true
) == true ->
"⚠️ Tidak ada koneksi internet. Silakan periksa koneksi Anda."
else ->
"⚠️ Terjadi kesalahan: ${e.message?.take(100) ?: "Unknown error"}"
}
} finally {
isLoading = false
}
}
}
},
containerColor = AppColors.Primary,
modifier = Modifier.size(48.dp)
) {
Icon(
Icons.Default.Send,
contentDescription = "Send",
tint = Color.White,
modifier = Modifier.size(20.dp)
)
}
}
}
}
}
}
}

View File

@ -1,250 +0,0 @@
package com.example.notesai.presentation.screens.ai.components
import androidx.compose.animation.*
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
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 com.example.notesai.data.model.ChatMessage
import com.example.notesai.util.MarkdownText
import com.example.notesai.util.MarkdownStripper
import com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
import java.text.SimpleDateFormat
import java.util.*
@Composable
fun ChatBubble(
message: ChatMessage,
onCopy: (String) -> Unit, // CHANGED: Sekarang terima text parameter
showCopied: Boolean
) {
val dateFormat = remember { SimpleDateFormat("HH:mm", Locale("id", "ID")) }
var showCopyMenu by remember { mutableStateOf(false) }
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = if (message.isUser) Alignment.End else Alignment.Start
) {
if (message.isUser) {
// User Message (tidak berubah)
Surface(
color = AppColors.Primary,
shape = RoundedCornerShape(
topStart = Constants.Radius.Large.dp,
topEnd = Constants.Radius.Large.dp,
bottomStart = Constants.Radius.Large.dp,
bottomEnd = 4.dp
),
shadowElevation = 2.dp,
modifier = Modifier.widthIn(max = 320.dp)
) {
Column(
modifier = Modifier.padding(12.dp)
) {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.Person,
contentDescription = null,
tint = Color.White.copy(alpha = 0.9f),
modifier = Modifier.size(16.dp)
)
Text(
"Anda",
color = Color.White.copy(alpha = 0.9f),
fontSize = 12.sp,
fontWeight = FontWeight.SemiBold
)
}
Spacer(modifier = Modifier.height(6.dp))
Text(
message.message,
color = Color.White,
style = MaterialTheme.typography.bodyMedium,
lineHeight = 20.sp
)
Spacer(modifier = Modifier.height(4.dp))
Text(
dateFormat.format(Date(message.timestamp)),
color = Color.White.copy(alpha = 0.7f),
fontSize = 11.sp
)
}
}
} else {
// AI Message with IMPROVED Copy Options
Surface(
color = AppColors.SurfaceVariant,
shape = RoundedCornerShape(
topStart = Constants.Radius.Large.dp,
topEnd = Constants.Radius.Large.dp,
bottomStart = 4.dp,
bottomEnd = Constants.Radius.Large.dp
),
shadowElevation = 2.dp,
modifier = Modifier.widthIn(max = 320.dp)
) {
Column(
modifier = Modifier.padding(12.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.SmartToy,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(16.dp)
)
Text(
"AI Assistant",
color = AppColors.OnSurfaceVariant,
fontSize = 12.sp,
fontWeight = FontWeight.SemiBold
)
}
// IMPROVED: Copy Button with Dropdown Menu
Box {
IconButton(
onClick = { showCopyMenu = !showCopyMenu },
modifier = Modifier.size(28.dp)
) {
AnimatedContent(
targetState = showCopied,
transitionSpec = {
fadeIn() + scaleIn() togetherWith fadeOut() + scaleOut()
},
label = "copy_icon"
) { copied ->
Icon(
if (copied) Icons.Default.Check else Icons.Default.ContentCopy,
contentDescription = if (copied) "Copied" else "Copy",
tint = if (copied) AppColors.Success else AppColors.OnSurfaceVariant,
modifier = Modifier.size(16.dp)
)
}
}
// Dropdown Menu untuk pilihan copy
DropdownMenu(
expanded = showCopyMenu,
onDismissRequest = { showCopyMenu = false },
modifier = Modifier.background(AppColors.SurfaceElevated)
) {
// Option 1: Copy dengan Format (Markdown)
DropdownMenuItem(
text = {
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.Code,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(18.dp)
)
Column {
Text(
"Copy dengan Format",
fontSize = 13.sp,
color = AppColors.OnSurface,
fontWeight = FontWeight.Medium
)
Text(
"Termasuk markdown",
fontSize = 10.sp,
color = AppColors.OnSurfaceTertiary
)
}
}
},
onClick = {
onCopy(message.message) // Copy original dengan markdown
showCopyMenu = false
}
)
HorizontalDivider(color = AppColors.Divider)
// Option 2: Copy Teks Asli (Plain Text)
DropdownMenuItem(
text = {
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.TextFields,
contentDescription = null,
tint = AppColors.Secondary,
modifier = Modifier.size(18.dp)
)
Column {
Text(
"Copy Teks Asli",
fontSize = 13.sp,
color = AppColors.OnSurface,
fontWeight = FontWeight.Medium
)
Text(
"Tanpa format",
fontSize = 10.sp,
color = AppColors.OnSurfaceTertiary
)
}
}
},
onClick = {
val plainText = MarkdownStripper.stripMarkdown(message.message)
onCopy(plainText) // Copy plain text tanpa markdown
showCopyMenu = false
}
)
}
}
}
Spacer(modifier = Modifier.height(8.dp))
// Use MarkdownText for AI responses
MarkdownText(
markdown = message.message,
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(4.dp))
Text(
dateFormat.format(Date(message.timestamp)),
color = AppColors.OnSurfaceTertiary,
fontSize = 11.sp
)
}
}
}
}
}

View File

@ -1,206 +0,0 @@
package com.example.notesai.presentation.screens.ai.components
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.*
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
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 com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
import com.example.notesai.util.FileParser
import com.example.notesai.util.FileParseResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@Composable
fun FileUploadButton(
onFileSelected: (FileParseResult.Success) -> Unit,
onError: (String) -> Unit,
modifier: Modifier = Modifier
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var isProcessing by remember { mutableStateOf(false) }
var selectedFileName by remember { mutableStateOf<String?>(null) }
// File picker launcher
val filePicker = rememberLauncherForActivityResult(
contract = ActivityResultContracts.GetContent()
) { uri: Uri? ->
uri?.let {
scope.launch {
isProcessing = true
try {
// Get file info
val fileSize = FileParser.getFileSize(context, uri)
// Check file size (max 10MB)
if (fileSize > 10 * 1024 * 1024) {
onError("File terlalu besar. Maksimal 10MB")
isProcessing = false
return@launch
}
// Parse file
val result = withContext(Dispatchers.IO) {
FileParser.parseFile(context, uri)
}
when (result) {
is FileParseResult.Success -> {
selectedFileName = result.fileName
onFileSelected(result)
}
is FileParseResult.Error -> {
onError(result.message)
}
}
} catch (e: Exception) {
onError("Gagal memproses file: ${e.message}")
} finally {
isProcessing = false
}
}
}
}
Button(
onClick = {
// Launch file picker untuk PDF, TXT, DOCX
filePicker.launch("*/*")
},
enabled = !isProcessing,
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Secondary.copy(alpha = 0.15f),
contentColor = AppColors.Secondary,
disabledContainerColor = AppColors.SurfaceVariant,
disabledContentColor = AppColors.OnSurfaceVariant
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp),
modifier = modifier,
contentPadding = PaddingValues(
horizontal = Constants.Spacing.Medium.dp,
vertical = Constants.Spacing.Small.dp
)
) {
if (isProcessing) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = AppColors.Secondary,
strokeWidth = 2.dp
)
Spacer(modifier = Modifier.width(8.dp))
Text("Memproses...")
} else {
Icon(
Icons.Default.AttachFile,
contentDescription = "Upload File",
modifier = Modifier.size(20.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Text(
"Upload File",
fontSize = 14.sp,
fontWeight = FontWeight.SemiBold
)
}
}
}
@Composable
fun FilePreviewCard(
fileResult: FileParseResult.Success,
onDismiss: () -> Unit,
modifier: Modifier = Modifier
) {
Surface(
modifier = modifier,
color = AppColors.SurfaceVariant,
shape = RoundedCornerShape(Constants.Radius.Large.dp),
shadowElevation = 4.dp
) {
Column(
modifier = Modifier.padding(16.dp)
) {
// Header
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
when (fileResult.fileType) {
"PDF" -> Icons.Default.PictureAsPdf
"Word" -> Icons.Default.Description
else -> Icons.Default.TextSnippet
},
contentDescription = null,
tint = AppColors.Secondary,
modifier = Modifier.size(24.dp)
)
Column {
Text(
fileResult.fileName,
fontWeight = FontWeight.Bold,
fontSize = 14.sp,
color = AppColors.OnSurface
)
Text(
"${fileResult.fileType}${fileResult.wordCount} kata",
fontSize = 12.sp,
color = AppColors.OnSurfaceTertiary
)
}
}
IconButton(
onClick = onDismiss,
modifier = Modifier.size(32.dp)
) {
Icon(
Icons.Default.Close,
contentDescription = "Close",
tint = AppColors.OnSurfaceVariant
)
}
}
Spacer(modifier = Modifier.height(12.dp))
// Content Preview
Surface(
color = AppColors.Surface,
shape = RoundedCornerShape(8.dp)
) {
Text(
fileResult.content.take(200) + if (fileResult.content.length > 200) "..." else "",
modifier = Modifier.padding(12.dp),
fontSize = 12.sp,
color = AppColors.OnSurfaceVariant,
lineHeight = 18.sp
)
}
}
}
}

View File

@ -1,58 +0,0 @@
package com.example.notesai.presentation.screens.ai.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Lightbulb
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
@Composable
fun SuggestionChip(
text: String,
onSelect: (String) -> Unit
) {
Surface(
onClick = { onSelect(text) },
color = AppColors.SurfaceVariant,
shape = RoundedCornerShape(12.dp)
) {
Row(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Icon(
Icons.Default.Lightbulb,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(16.dp)
)
Text(
text,
color = AppColors.OnSurface,
style = MaterialTheme.typography.bodyMedium,
fontSize = 14.sp
)
}
}
}

View File

@ -1,78 +0,0 @@
package com.example.notesai.presentation.screens.archive
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Archive
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.notesai.data.model.Note
import com.example.notesai.data.model.Category
import com.example.notesai.presentation.components.EmptyState
import com.example.notesai.presentation.screens.archive.components.ArchiveNoteCard
@Composable
fun ArchiveScreen(
notes: List<Note>,
categories: List<Category>,
searchQuery: String = "", // Tambahkan parameter ini
onRestore: (Note) -> Unit,
onDelete: (Note) -> Unit
) {
// Filter berdasarkan search query dari ModernTopBar
val filteredNotes = if (searchQuery.isBlank()) {
notes
} else {
notes.filter { note ->
note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true) ||
note.description.contains(searchQuery, ignoreCase = true) ||
categories.find { it.id == note.categoryId }?.name?.contains(searchQuery, ignoreCase = true) == true
}
}
Column(modifier = Modifier.fillMaxSize()) {
// Content
if (filteredNotes.isEmpty()) {
if (searchQuery.isNotEmpty()) {
EmptyState(
icon = Icons.Default.Search,
message = "Tidak ada hasil",
subtitle = "Coba kata kunci lain"
)
} else {
EmptyState(
icon = Icons.Default.Archive,
message = "Arsip kosong",
subtitle = "Catatan yang diarsipkan akan muncul di sini"
)
}
} else {
LazyColumn(
contentPadding = PaddingValues(
start = 16.dp,
end = 16.dp,
top = 8.dp,
bottom = 100.dp
),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(filteredNotes) { note ->
val category = categories.find { it.id == note.categoryId }
ArchiveNoteCard(
note = note,
categoryName = category?.name ?: "Unknown",
onRestore = { onRestore(note) },
onDelete = { onDelete(note) }
)
}
}
}
}
}

View File

@ -1,129 +0,0 @@
package com.example.notesai.presentation.screens.archive.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
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 com.example.notesai.data.model.Note
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
// Helper function untuk extract plain text dari AnnotatedString JSON
private fun extractPlainText(jsonContent: String): String {
return try {
if (jsonContent.trim().startsWith("{")) {
val jsonElement = Json.parseToJsonElement(jsonContent)
val jsonObject = jsonElement.jsonObject
jsonObject["text"]?.jsonPrimitive?.content ?: ""
} else {
jsonContent
}
} catch (e: Exception) {
jsonContent
}
}
@Composable
fun ArchiveNoteCard(
note: Note,
categoryName: String,
onRestore: () -> Unit,
onDelete: () -> Unit
) {
val displayContent = if (note.description.isNotEmpty()) {
note.description
} else {
extractPlainText(note.content)
}
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(
containerColor = Color(0xFF1E293B)
),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) {
Column(modifier = Modifier.padding(16.dp)) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(modifier = Modifier.weight(1f)) {
Text(
note.title,
fontWeight = FontWeight.Bold,
color = Color.White,
style = MaterialTheme.typography.titleMedium
)
Spacer(modifier = Modifier.height(4.dp))
Text(
categoryName,
color = Color(0xFF64748B),
style = MaterialTheme.typography.bodySmall
)
}
}
if (displayContent.isNotEmpty()) {
Spacer(modifier = Modifier.height(8.dp))
Text(
displayContent,
maxLines = 2,
color = Color(0xFF94A3B8),
style = MaterialTheme.typography.bodyMedium
)
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 12.dp),
horizontalArrangement = Arrangement.End
) {
TextButton(onClick = onRestore) {
Icon(
Icons.Default.AccountBox,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFF10B981)
)
Spacer(modifier = Modifier.width(4.dp))
Text("Pulihkan", color = Color(0xFF10B981), fontWeight = FontWeight.Bold)
}
Spacer(modifier = Modifier.width(8.dp))
TextButton(onClick = onDelete) {
Icon(
Icons.Default.Delete,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFFEF4444)
)
Spacer(modifier = Modifier.width(4.dp))
Text("Hapus", color = Color(0xFFEF4444), fontWeight = FontWeight.Bold)
}
}
}
}
}

View File

@ -1,150 +0,0 @@
package com.example.notesai.presentation.screens.main
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Create
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.notesai.data.model.Category
import com.example.notesai.data.model.Note
import com.example.notesai.presentation.components.EmptyState
import com.example.notesai.presentation.screens.main.components.CategoryCard
import com.example.notesai.presentation.screens.main.components.NoteCard
@Composable
fun MainScreen(
categories: List<Category>,
notes: List<Note>,
selectedCategory: Category?,
searchQuery: String,
onCategoryClick: (Category) -> Unit,
onNoteClick: (Note) -> Unit,
onPinToggle: (Note) -> Unit,
onCategoryDelete: (Category) -> Unit,
onCategoryEdit: (Category, String, Long, Long) -> Unit,
onCategoryPin: (Category) -> Unit, // NEW: Pin category callback
onNoteEdit: (Note) -> Unit = {},
onNoteDelete: (Note) -> Unit = {}
) {
Column(modifier = Modifier.fillMaxSize()) {
if (selectedCategory == null) {
// Beranda: Tampilkan kategori dengan search filtering
if (categories.isEmpty()) {
EmptyState(
icon = Icons.Default.Create,
message = "Buat kategori pertama Anda",
subtitle = "Tekan tombol + untuk memulai"
)
} else {
// Filter kategori berdasarkan searchQuery
val filteredCategories = if (searchQuery.isBlank()) {
categories
} else {
categories.filter { category ->
// 1. Cek nama kategori cocok
val categoryNameMatches = category.name.contains(searchQuery, ignoreCase = true)
// 2. Cek ada catatan yang cocok di kategori ini
val hasMatchingNotes = notes.any { note ->
note.categoryId == category.id &&
!note.isDeleted &&
!note.isArchived &&
(note.title.contains(searchQuery, ignoreCase = true) ||
note.description.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true))
}
// Kategori muncul jika salah satu kondisi terpenuhi
categoryNameMatches || hasMatchingNotes
}
}
if (filteredCategories.isEmpty()) {
EmptyState(
icon = Icons.Default.Search,
message = "Kategori tidak ditemukan",
subtitle = "Coba kata kunci lain"
)
} else {
LazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Fixed(2),
contentPadding = PaddingValues(
start = 16.dp,
end = 16.dp,
top = 16.dp,
bottom = 100.dp
),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalItemSpacing = 12.dp,
modifier = Modifier.fillMaxSize()
) {
items(filteredCategories) { category ->
CategoryCard(
category = category,
noteCount = notes.count {
it.categoryId == category.id &&
!it.isDeleted &&
!it.isArchived
},
onClick = { onCategoryClick(category) },
onDelete = { onCategoryDelete(category) },
onEdit = { name, gradientStart, gradientEnd ->
onCategoryEdit(category, name, gradientStart, gradientEnd)
},
onPin = { onCategoryPin(category) } // NEW: Pass pin callback
)
}
}
}
}
} else {
val categoryNotes = notes
.filter {
it.categoryId == selectedCategory.id &&
!it.isDeleted &&
!it.isArchived &&
(searchQuery.isEmpty() ||
it.title.contains(searchQuery, ignoreCase = true) ||
it.content.contains(searchQuery, ignoreCase = true))
}
.sortedWith(compareByDescending<Note> { it.isPinned }.thenByDescending { it.timestamp })
if (categoryNotes.isEmpty()) {
EmptyState(
icon = Icons.Default.Add,
message = if (searchQuery.isEmpty()) "Belum ada catatan" else "Tidak ada hasil",
subtitle = if (searchQuery.isEmpty()) "Tekan tombol + untuk membuat catatan" else "Coba kata kunci lain"
)
} else {
LazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Fixed(2),
contentPadding = PaddingValues(
start = 16.dp,
end = 16.dp,
top = 16.dp,
bottom = 100.dp
),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalItemSpacing = 12.dp,
modifier = Modifier.fillMaxSize()
) {
items(categoryNotes) { note ->
NoteCard(
note = note,
onClick = { onNoteClick(note) },
onPinClick = { onPinToggle(note) },
onEdit = { onNoteEdit(note) },
onDelete = { onNoteDelete(note) }
)
}
}
}
}
}
}

View File

@ -1,452 +0,0 @@
// File: presentation/screens/main/components/CategoryCard.kt
package com.example.notesai.presentation.screens.main.components
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.outlined.FolderOpen
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Brush
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 com.example.notesai.data.model.Category
import com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
@Composable
fun CategoryCard(
category: Category,
noteCount: Int,
onClick: () -> Unit,
onDelete: () -> Unit = {},
onEdit: (String, Long, Long) -> Unit = { _, _, _ -> },
onPin: () -> Unit = {}
) {
var showDeleteConfirm by remember { mutableStateOf(false) }
var showEditDialog by remember { mutableStateOf(false) }
var showMenu by remember { mutableStateOf(false) }
var isPressed by remember { mutableStateOf(false) }
// Smooth scale animation
val scale by animateFloatAsState(
targetValue = if (isPressed) 0.95f else 1f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
),
label = "scale"
)
// Delete Confirmation Dialog
if (showDeleteConfirm) {
AlertDialog(
onDismissRequest = { showDeleteConfirm = false },
title = {
Text(
"Pindahkan ke Sampah?",
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold
)
},
text = {
Text(
"Kategori '${category.name}' dan $noteCount catatan di dalamnya akan dipindahkan ke sampah.",
color = AppColors.OnSurfaceVariant
)
},
confirmButton = {
Button(
onClick = {
onDelete()
showDeleteConfirm = false
},
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Error
)
) {
Text("Hapus", color = Color.White)
}
},
dismissButton = {
TextButton(onClick = { showDeleteConfirm = false }) {
Text("Batal", color = AppColors.OnSurfaceVariant)
}
},
containerColor = AppColors.Surface,
shape = RoundedCornerShape(Constants.Radius.Large.dp)
)
}
// Edit Dialog
if (showEditDialog) {
EditCategoryDialog(
category = category,
onDismiss = { showEditDialog = false },
onSave = { name, gradientStart, gradientEnd ->
onEdit(name, gradientStart, gradientEnd)
showEditDialog = false
}
)
}
// Main Card - Minimalist Design
Card(
modifier = Modifier
.fillMaxWidth()
.scale(scale)
.clickable(onClick = onClick),
shape = RoundedCornerShape(Constants.Radius.Large.dp),
colors = CardDefaults.cardColors(
containerColor = AppColors.Surface
),
elevation = CardDefaults.cardElevation(
defaultElevation = Constants.Elevation.Small.dp
)
) {
Box(
modifier = Modifier
.fillMaxWidth()
.background(
brush = Brush.linearGradient(
colors = listOf(
Color(category.gradientStart).copy(alpha = 0.1f),
Color(category.gradientEnd).copy(alpha = 0.05f)
)
)
)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(Constants.Spacing.Large.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top
) {
// Icon dengan gradient accent
Box(
modifier = Modifier
.size(48.dp)
.clip(RoundedCornerShape(Constants.Radius.Medium.dp))
.background(
brush = Brush.linearGradient(
colors = listOf(
Color(category.gradientStart).copy(alpha = 0.2f),
Color(category.gradientEnd).copy(alpha = 0.1f)
)
)
),
contentAlignment = Alignment.Center
) {
Icon(
Icons.Outlined.FolderOpen,
contentDescription = null,
tint = Color(category.gradientStart),
modifier = Modifier.size(24.dp)
)
}
// Pin Indicator & Menu Button
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically
) {
// Pin indicator (only show if pinned)
AnimatedVisibility(
visible = category.isPinned,
enter = scaleIn() + fadeIn(),
exit = scaleOut() + fadeOut()
) {
Icon(
Icons.Default.PushPin,
contentDescription = "Pinned",
tint = AppColors.Warning,
modifier = Modifier.size(20.dp)
)
}
// Menu Button
Box {
IconButton(
onClick = { showMenu = true },
modifier = Modifier.size(32.dp)
) {
Icon(
Icons.Default.MoreVert,
contentDescription = "Menu",
tint = AppColors.OnSurfaceVariant,
modifier = Modifier.size(20.dp)
)
}
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false },
modifier = Modifier.background(AppColors.SurfaceElevated)
) {
// Pin/Unpin Menu Item
DropdownMenuItem(
text = {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Constants.Spacing.Small.dp)
) {
Icon(
Icons.Default.PushPin,
contentDescription = null,
tint = if (category.isPinned) AppColors.Warning else AppColors.OnSurfaceVariant,
modifier = Modifier.size(18.dp)
)
Text(
if (category.isPinned) "Lepas Pin" else "Pin Kategori",
color = AppColors.OnSurface,
fontSize = 14.sp
)
}
},
onClick = {
onPin()
showMenu = false
}
)
HorizontalDivider(color = AppColors.Divider)
// Edit Menu Item
DropdownMenuItem(
text = {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Constants.Spacing.Small.dp)
) {
Icon(
Icons.Default.Edit,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(18.dp)
)
Text(
"Edit Kategori",
color = AppColors.OnSurface,
fontSize = 14.sp
)
}
},
onClick = {
showMenu = false
showEditDialog = true
}
)
HorizontalDivider(color = AppColors.Divider)
// Delete Menu Item
DropdownMenuItem(
text = {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Constants.Spacing.Small.dp)
) {
Icon(
Icons.Default.Delete,
contentDescription = null,
tint = AppColors.Error,
modifier = Modifier.size(18.dp)
)
Text(
"Pindah ke Sampah",
color = AppColors.OnSurface,
fontSize = 14.sp
)
}
},
onClick = {
showMenu = false
showDeleteConfirm = true
}
)
}
}
}
}
Spacer(modifier = Modifier.height(Constants.Spacing.Medium.dp))
// Category Name
Text(
category.name,
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.Bold,
color = AppColors.OnBackground,
fontSize = 18.sp
)
Spacer(modifier = Modifier.height(Constants.Spacing.ExtraSmall.dp))
// Note Count dengan subtle styling
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
Icon(
Icons.Default.Description,
contentDescription = null,
tint = AppColors.OnSurfaceTertiary,
modifier = Modifier.size(14.dp)
)
Text(
"$noteCount catatan",
style = MaterialTheme.typography.bodySmall,
color = AppColors.OnSurfaceTertiary,
fontSize = 13.sp
)
}
}
}
}
}
@Composable
fun EditCategoryDialog(
category: Category,
onDismiss: () -> Unit,
onSave: (String, Long, Long) -> Unit
) {
var name by remember { mutableStateOf(category.name) }
var selectedGradient by remember {
mutableStateOf(
Constants.CategoryColors.indexOfFirst {
it.first == category.gradientStart && it.second == category.gradientEnd
}.takeIf { it >= 0 } ?: 0
)
}
AlertDialog(
onDismissRequest = onDismiss,
containerColor = AppColors.Surface,
shape = RoundedCornerShape(Constants.Radius.Large.dp),
title = {
Text(
"Edit Kategori",
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold
)
},
text = {
Column {
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = {
Text(
"Nama Kategori",
color = AppColors.OnSurfaceVariant
)
},
modifier = Modifier.fillMaxWidth(),
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = AppColors.OnBackground,
unfocusedTextColor = AppColors.OnSurface,
focusedContainerColor = AppColors.SurfaceVariant,
unfocusedContainerColor = AppColors.SurfaceVariant,
cursorColor = AppColors.Primary,
focusedBorderColor = AppColors.Primary,
unfocusedBorderColor = AppColors.Border
),
shape = RoundedCornerShape(Constants.Radius.Medium.dp)
)
Spacer(modifier = Modifier.height(20.dp))
Text(
"Pilih Warna:",
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurface,
fontWeight = FontWeight.SemiBold,
fontSize = 14.sp
)
Spacer(modifier = Modifier.height(12.dp))
// 8 colors in 2 rows
Constants.CategoryColors.chunked(4).forEach { row ->
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
row.forEachIndexed { _, gradient ->
val globalIndex = Constants.CategoryColors.indexOf(gradient)
val isSelected = selectedGradient == globalIndex
Box(
modifier = Modifier
.weight(1f)
.aspectRatio(1f)
.clip(RoundedCornerShape(Constants.Radius.Medium.dp))
.background(
brush = Brush.linearGradient(
colors = listOf(
Color(gradient.first),
Color(gradient.second)
)
)
)
.clickable { selectedGradient = globalIndex },
contentAlignment = Alignment.Center
) {
this@Row.AnimatedVisibility(
visible = isSelected,
enter = scaleIn() + fadeIn(),
exit = scaleOut() + fadeOut()
) {
Icon(
Icons.Default.Check,
contentDescription = null,
tint = Color.White,
modifier = Modifier.size(28.dp)
)
}
}
}
}
Spacer(modifier = Modifier.height(12.dp))
}
}
},
confirmButton = {
Button(
onClick = {
if (name.isNotBlank()) {
val gradient = Constants.CategoryColors[selectedGradient]
onSave(name, gradient.first, gradient.second)
}
},
enabled = name.isNotBlank(),
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Primary
)
) {
Text("Simpan", color = Color.White, fontWeight = FontWeight.Bold)
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text("Batal", color = AppColors.OnSurfaceVariant)
}
}
)
}

View File

@ -1,365 +0,0 @@
// File: presentation/screens/main/components/NoteCard.kt
package com.example.notesai.presentation.screens.main.components
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.notesai.data.model.Note
import com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
import java.text.SimpleDateFormat
import java.util.*
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun NoteCard(
note: Note,
onClick: () -> Unit,
onPinClick: () -> Unit,
onEdit: () -> Unit = {},
onDelete: () -> Unit = {}
) {
val dateFormat = SimpleDateFormat("dd MMM, HH:mm", Locale("id", "ID"))
var showMenu by remember { mutableStateOf(false) }
var showDeleteConfirm by remember { mutableStateOf(false) }
// Scale animation on press
var isPressed by remember { mutableStateOf(false) }
val scale by animateFloatAsState(
targetValue = if (isPressed) 0.95f else 1f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
),
label = "scale"
)
// Pin icon rotation animation
val pinRotation by animateFloatAsState(
targetValue = if (note.isPinned) 0f else 45f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessMedium
),
label = "rotation"
)
// Elevation animation for pinned state
val elevation by animateDpAsState(
targetValue = if (note.isPinned) Constants.Elevation.Medium.dp else Constants.Elevation.Small.dp,
animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy),
label = "elevation"
)
// Delete Confirmation Dialog
if (showDeleteConfirm) {
AlertDialog(
onDismissRequest = { showDeleteConfirm = false },
icon = {
Icon(
Icons.Default.DeleteForever,
contentDescription = null,
tint = AppColors.Error,
modifier = Modifier.size(32.dp)
)
},
title = {
Text(
"Pindahkan ke Sampah?",
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold
)
},
text = {
Text(
"Catatan '${note.title}' akan dipindahkan ke sampah.",
color = AppColors.OnSurfaceVariant
)
},
confirmButton = {
Button(
onClick = {
onDelete()
showDeleteConfirm = false
},
colors = ButtonDefaults.buttonColors(
containerColor = AppColors.Error
)
) {
Text("Hapus", color = Color.White)
}
},
dismissButton = {
TextButton(onClick = { showDeleteConfirm = false }) {
Text("Batal", color = AppColors.OnSurfaceVariant)
}
},
containerColor = AppColors.Surface,
shape = RoundedCornerShape(Constants.Radius.Large.dp)
)
}
Card(
modifier = Modifier
.fillMaxWidth()
.scale(scale)
.combinedClickable(onClick = onClick),
shape = RoundedCornerShape(Constants.Radius.Large.dp),
colors = CardDefaults.cardColors(
containerColor = if (note.isPinned)
AppColors.SurfaceVariant.copy(alpha = 0.95f)
else
AppColors.SurfaceVariant
),
elevation = CardDefaults.cardElevation(
defaultElevation = elevation
)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(Constants.Spacing.Large.dp)
) {
// Header: Title + Menu
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top
) {
// Title with pin badge
Row(
modifier = Modifier.weight(1f),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
note.title,
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.Bold,
color = AppColors.OnBackground,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
fontSize = 18.sp,
modifier = Modifier.weight(1f, fill = false)
)
// Pin Badge next to title
AnimatedVisibility(
visible = note.isPinned,
enter = scaleIn(spring(dampingRatio = Spring.DampingRatioMediumBouncy)) + fadeIn(),
exit = scaleOut(spring(dampingRatio = Spring.DampingRatioMediumBouncy)) + fadeOut()
) {
Surface(
color = AppColors.Warning.copy(alpha = 0.2f),
shape = RoundedCornerShape(Constants.Radius.Small.dp)
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp),
modifier = Modifier.padding(horizontal = 6.dp, vertical = 3.dp)
) {
Icon(
Icons.Filled.PushPin,
contentDescription = "Disematkan",
tint = AppColors.Warning,
modifier = Modifier
.size(12.dp)
.rotate(45f)
)
Text(
"Pin",
fontSize = 10.sp,
fontWeight = FontWeight.Bold,
color = AppColors.Warning
)
}
}
}
}
// Menu Button
Box {
IconButton(
onClick = { showMenu = true },
modifier = Modifier.size(32.dp)
) {
Icon(
Icons.Default.MoreVert,
contentDescription = "Menu",
tint = AppColors.OnSurfaceVariant,
modifier = Modifier.size(20.dp)
)
}
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false },
modifier = Modifier.background(AppColors.SurfaceElevated)
) {
// Pin/Unpin option
DropdownMenuItem(
text = {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Constants.Spacing.Small.dp)
) {
Icon(
Icons.Filled.PushPin,
contentDescription = null,
tint = if (note.isPinned) AppColors.Warning else AppColors.Primary,
modifier = Modifier
.size(18.dp)
.rotate(pinRotation)
)
Text(
if (note.isPinned) "Lepas Sematan" else "Sematkan",
color = AppColors.OnSurface,
fontSize = 14.sp
)
}
},
onClick = {
showMenu = false
onPinClick()
}
)
HorizontalDivider(color = AppColors.Divider)
DropdownMenuItem(
text = {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Constants.Spacing.Small.dp)
) {
Icon(
Icons.Default.Edit,
contentDescription = null,
tint = AppColors.Primary,
modifier = Modifier.size(18.dp)
)
Text(
"Edit Catatan",
color = AppColors.OnSurface,
fontSize = 14.sp
)
}
},
onClick = {
showMenu = false
onEdit()
}
)
DropdownMenuItem(
text = {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Constants.Spacing.Small.dp)
) {
Icon(
Icons.Default.Delete,
contentDescription = null,
tint = AppColors.Error,
modifier = Modifier.size(18.dp)
)
Text(
"Pindah ke Sampah",
color = AppColors.OnSurface,
fontSize = 14.sp
)
}
},
onClick = {
showMenu = false
showDeleteConfirm = true
}
)
}
}
}
// Description Preview
if (note.description.isNotEmpty()) {
Spacer(modifier = Modifier.height(12.dp))
Text(
note.description,
style = MaterialTheme.typography.bodyMedium,
maxLines = 3,
overflow = TextOverflow.Ellipsis,
color = AppColors.OnSurfaceVariant,
lineHeight = 20.sp,
fontSize = 14.sp
)
} else {
Spacer(modifier = Modifier.height(12.dp))
Text(
"Tidak ada deskripsi",
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurfaceVariant.copy(alpha = 0.5f),
fontStyle = androidx.compose.ui.text.font.FontStyle.Italic,
fontSize = 14.sp
)
}
Spacer(modifier = Modifier.height(16.dp))
// Divider
HorizontalDivider(
color = AppColors.Divider,
thickness = 1.dp
)
Spacer(modifier = Modifier.height(12.dp))
// Footer: Timestamp
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
dateFormat.format(Date(note.timestamp)),
style = MaterialTheme.typography.bodySmall,
color = AppColors.OnSurfaceTertiary,
fontSize = 12.sp
)
// Pin indicator icon in footer
AnimatedVisibility(
visible = note.isPinned,
enter = fadeIn() + expandHorizontally(),
exit = fadeOut() + shrinkHorizontally()
) {
Icon(
Icons.Filled.PushPin,
contentDescription = "Disematkan",
tint = AppColors.Warning.copy(alpha = 0.6f),
modifier = Modifier
.size(14.dp)
.rotate(45f)
)
}
}
}
}
}

View File

@ -1,323 +0,0 @@
package com.example.notesai.presentation.screens.note
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.relocation.BringIntoViewRequester
import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.foundation.layout.imeNestedScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.outlined.StarBorder
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.*
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.*
import com.example.notesai.data.model.Note
import com.example.notesai.presentation.screens.note.components.DraggableMiniMarkdownToolbar
import com.example.notesai.presentation.screens.note.editor.RichEditorState
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.*
import kotlin.math.roundToInt
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@Composable
fun EditableFullScreenNoteView(
note: Note,
onBack: () -> Unit,
onSave: (String, String) -> Unit,
onArchive: () -> Unit,
onDelete: () -> Unit,
onPinToggle: () -> Unit
) {
var title by remember { mutableStateOf(note.title) }
var isContentFocused by remember { mutableStateOf(false) }
val editorState = remember(note.id) {
RichEditorState(
AnnotatedStringSerializer.fromJson(note.content)
)
}
val focusRequester = remember { FocusRequester() }
val bringIntoViewRequester = remember { BringIntoViewRequester() }
val scrollState = rememberScrollState()
val scope = rememberCoroutineScope()
val keyboard = LocalSoftwareKeyboardController.current
fun ensureFocus() {
focusRequester.requestFocus()
keyboard?.show()
}
fun saveNote() {
if (title.isNotBlank()) {
onSave(
title,
AnnotatedStringSerializer.toJson(editorState.value.annotatedString)
)
}
}
// AUTO SAVE SAAT APP BACKGROUND / KELUAR
val lifecycleOwner = LocalLifecycleOwner.current
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_STOP) {
saveNote()
}
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
val dateFormat = remember {
SimpleDateFormat("dd MMMM yyyy, HH:mm", Locale("id", "ID"))
}
val density = LocalDensity.current
val config = LocalConfiguration.current
val screenWidthPx = with(density) { config.screenWidthDp.dp.toPx() }
val screenHeightPx = with(density) { config.screenHeightDp.dp.toPx() }
val marginPx = with(density) { 16.dp.toPx() }
val imeBottomPx = with(density) {
WindowInsets.ime.getBottom(this).toFloat()
}
var toolbarSizePx by remember {
mutableStateOf(androidx.compose.ui.geometry.Size.Zero)
}
var toolbarOffset by remember {
mutableStateOf(Offset(marginPx, screenHeightPx * 0.6f))
}
fun moveToolbar(dx: Float, dy: Float) {
toolbarOffset = toolbarOffset.copy(
x = toolbarOffset.x + dx,
y = toolbarOffset.y + dy
)
}
Box(modifier = Modifier.fillMaxSize()) {
Scaffold(
topBar = {
TopAppBar(
navigationIcon = {
IconButton(onClick = {
saveNote()
onBack()
}) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, null)
}
},
title = {},
actions = {
IconButton(onClick = {
saveNote()
onPinToggle()
}) {
Icon(
if (note.isPinned) Icons.Filled.Star
else Icons.Outlined.StarBorder,
contentDescription = null,
tint = if (note.isPinned) Color(0xFFFFB300) else MaterialTheme.colorScheme.onSurface
)
}
IconButton(onClick = onArchive) {
Icon(
Icons.Default.Archive,
contentDescription = null,
tint = Color(0xFF4CAF50)
)
}
IconButton(onClick = onDelete) {
Icon(
Icons.Default.Delete,
contentDescription = null,
tint = Color(0xFFF44336)
)
}
}
)
},
contentWindowInsets = WindowInsets(0)
) { paddingValues ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
.imeNestedScroll()
.verticalScroll(scrollState)
.padding(horizontal = 20.dp)
.padding(
bottom = WindowInsets.ime
.asPaddingValues()
.calculateBottomPadding()
)
) {
// FIXED: BasicTextField untuk judul agar sejajar dengan konten
BasicTextField(
value = title,
onValueChange = { title = it },
textStyle = MaterialTheme.typography.headlineLarge.copy(
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onBackground
),
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp),
decorationBox = { innerTextField ->
Box {
if (title.isEmpty()) {
Text(
"Judul",
style = MaterialTheme.typography.headlineLarge.copy(
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.4f)
)
)
}
innerTextField()
}
}
)
Spacer(Modifier.height(12.dp))
Text(
"Terakhir diubah: ${dateFormat.format(Date(note.timestamp))}",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.6f)
)
HorizontalDivider(Modifier.padding(vertical = 20.dp))
// Konten editor
BasicTextField(
value = editorState.value,
onValueChange = {
editorState.onValueChange(it)
scope.launch {
bringIntoViewRequester.bringIntoView()
}
},
cursorBrush = SolidColor(Color(0xFFA855F7)),
textStyle = MaterialTheme.typography.bodyLarge.copy(
color = MaterialTheme.colorScheme.onBackground,
lineHeight = 28.sp
),
modifier = Modifier
.fillMaxWidth()
.defaultMinSize(minHeight = 400.dp)
.focusRequester(focusRequester)
.bringIntoViewRequester(bringIntoViewRequester)
.onFocusChanged {
isContentFocused = it.isFocused
if (it.isFocused) {
scope.launch { bringIntoViewRequester.bringIntoView() }
}
},
decorationBox = { innerTextField ->
Box {
if (editorState.value.text.isEmpty()) {
Text(
"Mulai menulis...",
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.4f)
)
}
innerTextField()
}
}
)
Spacer(Modifier.height(180.dp))
}
}
// GANTI SELURUH bagian DraggableMiniMarkdownToolbar di EditableFullScreenNoteView.kt
// Letakkan kode ini di dalam Box setelah Scaffold, sebelum closing bracket
if (isContentFocused) {
DraggableMiniMarkdownToolbar(
modifier = Modifier
.align(Alignment.TopStart)
.offset {
val maxX =
(screenWidthPx - toolbarSizePx.width - marginPx)
.coerceAtLeast(marginPx)
val maxY =
(screenHeightPx - imeBottomPx - toolbarSizePx.height)
.coerceAtLeast(marginPx)
IntOffset(
toolbarOffset.x.coerceIn(marginPx, maxX).roundToInt(),
toolbarOffset.y.coerceIn(marginPx, maxY).roundToInt()
)
}
.onSizeChanged {
toolbarSizePx = androidx.compose.ui.geometry.Size(
it.width.toFloat(),
it.height.toFloat()
)
},
isBoldActive = editorState.isBoldActive(),
isItalicActive = editorState.isItalicActive(),
isUnderlineActive = editorState.isUnderlineActive(),
canUndo = editorState.canUndo(),
canRedo = editorState.canRedo(),
onDrag = ::moveToolbar,
onBold = {
ensureFocus()
editorState.toggleBold()
},
onItalic = {
ensureFocus()
editorState.toggleItalic()
},
onUnderline = {
ensureFocus()
editorState.toggleUnderline()
},
onUndo = {
editorState.undo()
},
onRedo = {
editorState.redo()
}
)
}
}
}

View File

@ -1,150 +0,0 @@
package com.example.notesai.presentation.screens.note.components
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
@Composable
fun DraggableMiniMarkdownToolbar(
modifier: Modifier = Modifier,
onDrag: (dx: Float, dy: Float) -> Unit,
// STATE
isBoldActive: Boolean,
isItalicActive: Boolean,
isUnderlineActive: Boolean,
canUndo: Boolean = false,
canRedo: Boolean = false,
// ACTIONS
onBold: () -> Unit,
onItalic: () -> Unit,
onUnderline: () -> Unit,
onUndo: () -> Unit = {},
onRedo: () -> Unit = {}
) {
Surface(
modifier = modifier,
shape = RoundedCornerShape(24.dp),
color = MaterialTheme.colorScheme.surface.copy(alpha = 0.95f),
shadowElevation = 6.dp
) {
Row(
modifier = Modifier.padding(horizontal = 8.dp, vertical = 6.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp)
) {
// 🔹 DRAG HANDLE
Box(
modifier = Modifier
.size(36.dp)
.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consume()
onDrag(dragAmount.x, dragAmount.y)
}
},
contentAlignment = Alignment.Center
) {
Icon(
Icons.Default.DragIndicator,
contentDescription = "Drag",
tint = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.4f),
modifier = Modifier.size(18.dp)
)
}
ToolbarIcon(
icon = Icons.Default.FormatBold,
isActive = isBoldActive,
onClick = onBold
)
ToolbarIcon(
icon = Icons.Default.FormatItalic,
isActive = isItalicActive,
onClick = onItalic
)
ToolbarIcon(
icon = Icons.Default.FormatUnderlined,
isActive = isUnderlineActive,
onClick = onUnderline
)
// Divider
Box(
modifier = Modifier
.width(1.dp)
.height(24.dp)
.background(MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f))
)
// Undo
ToolbarIcon(
icon = Icons.Default.Undo,
onClick = onUndo,
enabled = canUndo
)
// Redo
ToolbarIcon(
icon = Icons.Default.Redo,
onClick = onRedo,
enabled = canRedo
)
}
}
}
@Composable
private fun ToolbarIcon(
icon: androidx.compose.ui.graphics.vector.ImageVector,
onClick: () -> Unit,
isActive: Boolean = false,
enabled: Boolean = true
) {
val activeBg = MaterialTheme.colorScheme.primary.copy(alpha = 0.15f)
val activeColor = MaterialTheme.colorScheme.primary
val disabledColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.3f)
Box(
modifier = Modifier
.size(36.dp)
.background(
color = if (isActive) activeBg else androidx.compose.ui.graphics.Color.Transparent,
shape = RoundedCornerShape(10.dp)
),
contentAlignment = Alignment.Center
) {
IconButton(
onClick = onClick,
modifier = Modifier.size(36.dp),
enabled = enabled
) {
Icon(
icon,
contentDescription = null,
tint = when {
!enabled -> disabledColor
isActive -> activeColor
else -> MaterialTheme.colorScheme.onSurface
},
modifier = Modifier.size(18.dp)
)
}
}
}

View File

@ -1,361 +0,0 @@
package com.example.notesai.presentation.screens.note.editor
import androidx.compose.runtime.*
import androidx.compose.ui.text.*
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.input.TextFieldValue
@Stable
class RichEditorState(initial: AnnotatedString) {
var value by mutableStateOf(
TextFieldValue(
annotatedString = initial,
selection = TextRange(initial.length)
)
)
/* =====================
UNDO / REDO
===================== */
private val undoStack = mutableStateListOf<TextFieldValue>()
private val redoStack = mutableStateListOf<TextFieldValue>()
private fun snapshot() {
undoStack.add(value)
redoStack.clear()
}
fun canUndo() = undoStack.isNotEmpty()
fun canRedo() = redoStack.isNotEmpty()
fun undo() {
if (!canUndo()) return
redoStack.add(value)
value = undoStack.removeAt(undoStack.lastIndex)
}
fun redo() {
if (!canRedo()) return
undoStack.add(value)
value = redoStack.removeAt(redoStack.lastIndex)
}
/* =====================
STICKY TYPING STYLE
===================== */
private val activeStyles = mutableStateListOf<SpanStyle>()
/* =====================
VALUE CHANGE
===================== */
fun onValueChange(newValue: TextFieldValue) {
val old = value
// cursor/selection change only
if (newValue.text == old.text) {
value = old.copy(
selection = newValue.selection,
composition = newValue.composition
)
return
}
snapshot()
// Build new annotated string by preserving old spans
val built = buildPreservingSpans(old, newValue)
// Auto-convert markdown patterns
val converted = autoConvertMarkdown(built)
value = converted
}
private fun buildPreservingSpans(old: TextFieldValue, newValue: TextFieldValue): TextFieldValue {
val builder = AnnotatedString.Builder(newValue.text)
val oldText = old.text
val newText = newValue.text
// Detect where text was inserted/deleted
val oldLen = oldText.length
val newLen = newText.length
val delta = newLen - oldLen
// Find insertion/deletion point
var changeStart = 0
while (changeStart < minOf(oldLen, newLen) &&
oldText.getOrNull(changeStart) == newText.getOrNull(changeStart)) {
changeStart++
}
val changeEnd = changeStart + maxOf(0, -delta)
// Copy and adjust old spans
old.annotatedString.spanStyles.forEach { r ->
var start = r.start
var end = r.end
// Adjust span positions based on where text changed
when {
// Span is completely before change
end <= changeStart -> {
// No adjustment needed
}
// Span is completely after change
start >= changeEnd -> {
start += delta
end += delta
}
// Span contains the change point
start < changeStart && end > changeEnd -> {
end += delta
}
// Span starts before change, ends in change area
start < changeStart && end in (changeStart + 1)..changeEnd -> {
end = changeStart
}
// Span starts in change area, ends after
start in changeStart until changeEnd && end >= changeEnd -> {
start = changeStart + delta
end += delta
}
// Span is completely inside change area - skip it
else -> return@forEach
}
// Clamp to valid range
start = start.coerceIn(0, newLen)
end = end.coerceIn(0, newLen)
if (start < end) {
builder.addStyle(r.item, start, end)
}
}
// Apply sticky styles to newly inserted character(s)
if (delta > 0 && activeStyles.isNotEmpty()) {
val insertStart = changeStart
val insertEnd = (changeStart + delta).coerceIn(0, newLen)
if (insertStart < insertEnd) {
activeStyles.forEach { st ->
builder.addStyle(st, insertStart, insertEnd)
}
}
}
return TextFieldValue(
annotatedString = builder.toAnnotatedString(),
selection = newValue.selection,
composition = newValue.composition
)
}
/* =====================
TOOLBAR TOGGLES
===================== */
fun toggleBold() = toggleStyle(SpanStyle(fontWeight = FontWeight.Bold))
fun toggleItalic() = toggleStyle(SpanStyle(fontStyle = FontStyle.Italic))
fun toggleUnderline() = toggleStyle(SpanStyle(textDecoration = TextDecoration.Underline))
private fun toggleStyle(style: SpanStyle) {
val sel = value.selection.normalized()
snapshot()
if (!sel.collapsed) applyStyleToSelection(style)
else toggleTypingStyle(style)
}
private fun toggleTypingStyle(style: SpanStyle) {
val idx = activeStyles.indexOfFirst { it.hasSameStyle(style) }
if (idx >= 0) activeStyles.removeAt(idx) else activeStyles.add(style)
}
private fun applyStyleToSelection(style: SpanStyle) {
val sel = value.selection.normalized()
val start = sel.start
val end = sel.end
if (start >= end) return
val builder = AnnotatedString.Builder(value.text)
value.annotatedString.spanStyles.forEach { r ->
val overlap = r.start < end && r.end > start
val same = r.item.hasSameStyle(style)
if (!(overlap && same)) builder.addStyle(r.item, r.start, r.end)
}
builder.addStyle(style, start, end)
value = value.copy(
annotatedString = builder.toAnnotatedString(),
selection = TextRange(end)
)
}
/* =====================
AUTO-CONVERT MARKDOWN
===================== */
private fun autoConvertMarkdown(v: TextFieldValue): TextFieldValue {
var cur = v
// Bold before italic to avoid conflicts
cur = convertBold(cur)
cur = convertItalic(cur)
return cur
}
// **word** -> bold(word), remove ** **
private fun convertBold(v: TextFieldValue): TextFieldValue {
val text = v.text
val cursor = v.selection.start
if (cursor < 2) return v
if (!(text.getOrNull(cursor - 1) == '*' && text.getOrNull(cursor - 2) == '*')) return v
val startMarker = text.lastIndexOf("**", startIndex = cursor - 3)
if (startMarker == -1) return v
val contentStart = startMarker + 2
val contentEnd = cursor - 2
if (contentEnd <= contentStart) return v
if (text.substring(contentStart, contentEnd).contains('\n')) return v
// Remove end marker then start marker
var out = v
out = replaceTextPreserveSpansLocal(out, cursor - 2, cursor, "")
out = replaceTextPreserveSpansLocal(out, startMarker, startMarker + 2, "")
// Apply bold style
val newStart = startMarker
val newEnd = contentEnd - 2
out = addStylePreserve(out, SpanStyle(fontWeight = FontWeight.Bold), newStart, newEnd)
// Adjust cursor
out = out.copy(selection = TextRange((cursor - 4).coerceAtLeast(newEnd)))
return out
}
// *word* -> italic(word), remove * *
private fun convertItalic(v: TextFieldValue): TextFieldValue {
val text = v.text
val cursor = v.selection.start
if (cursor < 1) return v
// Avoid triggering on bold closing (**)
if (text.getOrNull(cursor - 1) != '*') return v
if (text.getOrNull(cursor - 2) == '*') return v
val startMarker = text.lastIndexOf('*', startIndex = cursor - 2)
if (startMarker == -1) return v
// Avoid ** as start
if (text.getOrNull(startMarker - 1) == '*') return v
val contentStart = startMarker + 1
val contentEnd = cursor - 1
if (contentEnd <= contentStart) return v
if (text.substring(contentStart, contentEnd).contains('\n')) return v
var out = v
out = replaceTextPreserveSpansLocal(out, cursor - 1, cursor, "")
out = replaceTextPreserveSpansLocal(out, startMarker, startMarker + 1, "")
val newStart = startMarker
val newEnd = contentEnd - 1
out = addStylePreserve(out, SpanStyle(fontStyle = FontStyle.Italic), newStart, newEnd)
out = out.copy(selection = TextRange((cursor - 2).coerceAtLeast(newEnd)))
return out
}
/* =====================
TOOLBAR STATE
===================== */
fun isBoldActive() = isStyleActive(fontWeight = FontWeight.Bold)
fun isItalicActive() = isStyleActive(fontStyle = FontStyle.Italic)
fun isUnderlineActive() = isStyleActive(decoration = TextDecoration.Underline)
private fun isStyleActive(
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
decoration: TextDecoration? = null
): Boolean {
val sel = value.selection
if (!sel.collapsed) {
return value.annotatedString.spanStyles.any {
it.start <= sel.start &&
it.end >= sel.end &&
(fontWeight == null || it.item.fontWeight == fontWeight) &&
(fontStyle == null || it.item.fontStyle == fontStyle) &&
(decoration == null || it.item.textDecoration == decoration)
}
}
return activeStyles.any {
(fontWeight == null || it.fontWeight == fontWeight) &&
(fontStyle == null || it.fontStyle == fontStyle) &&
(decoration == null || it.textDecoration == decoration)
}
}
/* =====================
INTERNAL: text replace while preserving spans
===================== */
private fun replaceTextPreserveSpansLocal(
v: TextFieldValue,
start: Int,
end: Int,
replacement: String
): TextFieldValue {
val oldText = v.text
val s = start.coerceIn(0, oldText.length)
val e = end.coerceIn(0, oldText.length)
if (s > e) return v
val newText = oldText.substring(0, s) + replacement + oldText.substring(e)
val delta = replacement.length - (e - s)
val b = AnnotatedString.Builder(newText)
v.annotatedString.spanStyles.forEach { r ->
var rs = r.start
var re = r.end
// Adjust spans
when {
re <= s -> Unit
rs >= e -> { rs += delta; re += delta }
rs < s && re > e -> re += delta
rs < s && re in (s + 1)..e -> re = s
rs in s until e && re > e -> { rs = s + replacement.length; re += delta }
else -> return@forEach
}
rs = rs.coerceIn(0, newText.length)
re = re.coerceIn(0, newText.length)
if (rs < re) b.addStyle(r.item, rs, re)
}
return v.copy(annotatedString = b.toAnnotatedString())
}
private fun addStylePreserve(v: TextFieldValue, style: SpanStyle, start: Int, end: Int): TextFieldValue {
val s = start.coerceIn(0, v.text.length)
val e = end.coerceIn(0, v.text.length)
if (s >= e) return v
val b = AnnotatedString.Builder(v.text)
v.annotatedString.spanStyles.forEach { r -> b.addStyle(r.item, r.start, r.end) }
b.addStyle(style, s, e)
return v.copy(annotatedString = b.toAnnotatedString())
}
}
/* =====================
HELPERS
===================== */
private fun SpanStyle.hasSameStyle(other: SpanStyle): Boolean =
fontWeight == other.fontWeight &&
fontStyle == other.fontStyle &&
textDecoration == other.textDecoration
private fun TextRange.normalized(): TextRange =
if (start <= end) this else TextRange(end, start)

View File

@ -1,83 +0,0 @@
package com.example.notesai.presentation.screens.starred
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.notesai.presentation.components.EmptyState
import com.example.notesai.presentation.screens.starred.components.StarredNoteCard
import com.example.notesai.data.model.Note
import com.example.notesai.data.model.Category
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun StarredNotesScreen(
notes: List<Note>,
categories: List<Category>,
searchQuery: String = "", // Tambahkan parameter ini
onNoteClick: (Note) -> Unit,
onUnpin: (Note) -> Unit
) {
val starredNotes = notes
.filter { it.isPinned && !it.isArchived && !it.isDeleted }
.sortedByDescending { it.timestamp }
// Filter berdasarkan search query dari ModernTopBar
val filteredNotes = if (searchQuery.isBlank()) {
starredNotes
} else {
starredNotes.filter { note ->
note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true) ||
note.description.contains(searchQuery, ignoreCase = true)
}
}
Column(modifier = Modifier.fillMaxSize()) {
// Content
if (filteredNotes.isEmpty()) {
if (searchQuery.isNotEmpty()) {
EmptyState(
icon = Icons.Default.Search,
message = "Tidak ada hasil",
subtitle = "Coba kata kunci lain"
)
} else {
EmptyState(
icon = Icons.Default.Star,
message = "Belum ada catatan berbintang",
subtitle = "Catatan yang ditandai berbintang akan muncul di sini"
)
}
} else {
LazyColumn(
contentPadding = PaddingValues(
start = 16.dp,
end = 16.dp,
top = 8.dp,
bottom = 100.dp
),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(filteredNotes) { note ->
val category = categories.find { it.id == note.categoryId }
StarredNoteCard(
note = note,
categoryName = category?.name ?: "Unknown",
onClick = { onNoteClick(note) },
onUnpin = { onUnpin(note) }
)
}
}
}
}
}

View File

@ -1,160 +0,0 @@
package com.example.notesai.presentation.screens.starred.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.outlined.StarBorder
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.example.notesai.data.model.Note
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
// Helper function untuk extract plain text dari AnnotatedString JSON
private fun extractPlainText(jsonContent: String): String {
return try {
if (jsonContent.trim().startsWith("{")) {
val jsonElement = Json.parseToJsonElement(jsonContent)
val jsonObject = jsonElement.jsonObject
// Extract field "text" yang berisi plain text content
jsonObject["text"]?.jsonPrimitive?.content ?: ""
} else {
jsonContent
}
} catch (e: Exception) {
// Jika parsing gagal, coba tampilkan content mentah
jsonContent
}
}
@Composable
fun StarredNoteCard(
note: Note,
categoryName: String,
onClick: () -> Unit,
onUnpin: () -> Unit
) {
// Gunakan description jika ada, jika tidak extract dari content JSON
val displayContent = if (note.description.isNotEmpty()) {
note.description
} else {
extractPlainText(note.content)
}
Card(
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onClick),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(
containerColor = Color(0xFF1E293B)
),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) {
Column(modifier = Modifier.padding(16.dp)) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top
) {
Column(modifier = Modifier.weight(1f)) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.Star,
contentDescription = null,
tint = Color(0xFFFBBF24),
modifier = Modifier.size(16.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Text(
note.title,
fontWeight = FontWeight.Bold,
color = Color.White,
style = MaterialTheme.typography.titleMedium
)
}
Spacer(modifier = Modifier.height(4.dp))
Text(
categoryName,
color = Color(0xFF64748B),
style = MaterialTheme.typography.bodySmall
)
}
}
if (displayContent.isNotEmpty()) {
Spacer(modifier = Modifier.height(8.dp))
Text(
displayContent,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
color = Color(0xFF94A3B8),
style = MaterialTheme.typography.bodyMedium
)
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 12.dp),
horizontalArrangement = Arrangement.End
) {
TextButton(onClick = onClick) {
Icon(
Icons.Default.Info,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFF6366F1)
)
Spacer(modifier = Modifier.width(4.dp))
Text(
"Lihat Detail",
color = Color(0xFF6366F1),
fontWeight = FontWeight.Bold
)
}
Spacer(modifier = Modifier.width(8.dp))
TextButton(onClick = onUnpin) {
Icon(
Icons.Outlined.StarBorder,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFFFBBF24)
)
Spacer(modifier = Modifier.width(4.dp))
Text(
"Hapus Bintang",
color = Color(0xFFFBBF24),
fontWeight = FontWeight.Bold
)
}
}
}
}
}

View File

@ -1,136 +0,0 @@
package com.example.notesai.presentation.screens.trash
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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 com.example.notesai.presentation.components.EmptyState
import com.example.notesai.presentation.screens.trash.components.TrashNoteCard
import com.example.notesai.presentation.screens.trash.components.TrashCategoryCard
import com.example.notesai.data.model.Note
import com.example.notesai.data.model.Category
@Composable
fun TrashScreen(
notes: List<Note>,
categories: List<Category>,
searchQuery: String = "", // Tambahkan parameter ini
onRestoreNote: (Note) -> Unit,
onDeleteNotePermanent: (Note) -> Unit,
onRestoreCategory: (Category) -> Unit,
onDeleteCategoryPermanent: (Category) -> Unit
) {
// Filter kategori dan note yang dihapus
val deletedCategories = categories.filter { it.isDeleted }
val deletedNotes = notes.filter { it.isDeleted }
// Filter berdasarkan search query dari ModernTopBar
val filteredCategories = if (searchQuery.isBlank()) {
deletedCategories
} else {
deletedCategories.filter { category ->
category.name.contains(searchQuery, ignoreCase = true)
}
}
val filteredNotes = if (searchQuery.isBlank()) {
deletedNotes
} else {
deletedNotes.filter { note ->
note.title.contains(searchQuery, ignoreCase = true) ||
note.content.contains(searchQuery, ignoreCase = true) ||
note.description.contains(searchQuery, ignoreCase = true) ||
categories.find { it.id == note.categoryId }?.name?.contains(searchQuery, ignoreCase = true) == true
}
}
Column(modifier = Modifier.fillMaxSize()) {
// Content
if (filteredCategories.isEmpty() && filteredNotes.isEmpty()) {
if (searchQuery.isNotEmpty()) {
EmptyState(
icon = Icons.Default.Search,
message = "Tidak ada hasil",
subtitle = "Coba kata kunci lain"
)
} else {
EmptyState(
icon = Icons.Default.Delete,
message = "Sampah kosong",
subtitle = "Kategori dan catatan yang dihapus akan muncul di sini"
)
}
} else {
LazyColumn(
contentPadding = PaddingValues(
start = 16.dp,
end = 16.dp,
top = 8.dp,
bottom = 100.dp
),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
// Section: Kategori Terhapus
if (filteredCategories.isNotEmpty()) {
item {
Text(
"Kategori Terhapus (${filteredCategories.size})",
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Bold,
color = Color(0xFF94A3B8),
modifier = Modifier.padding(vertical = 8.dp)
)
}
items(filteredCategories) { category ->
val notesInCategory = notes.count {
it.categoryId == category.id && it.isDeleted
}
TrashCategoryCard(
category = category,
noteCount = notesInCategory,
onRestore = { onRestoreCategory(category) },
onDeletePermanent = { onDeleteCategoryPermanent(category) }
)
}
}
// Section: Catatan Terhapus
if (filteredNotes.isNotEmpty()) {
item {
Text(
"Catatan Terhapus (${filteredNotes.size})",
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Bold,
color = Color(0xFF94A3B8),
modifier = Modifier.padding(vertical = 8.dp)
)
}
items(filteredNotes) { note ->
val category = categories.find { it.id == note.categoryId }
TrashNoteCard(
note = note,
categoryName = category?.name ?: "Unknown",
onRestore = { onRestoreNote(note) },
onDeletePermanent = { onDeleteNotePermanent(note) }
)
}
}
}
}
}
}

View File

@ -1,160 +0,0 @@
// File: presentation/screens/trash/components/TrashCategoryCard.kt
package com.example.notesai.presentation.screens.trash.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Folder
import androidx.compose.material.icons.filled.Restore
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.example.notesai.data.model.Category
@Composable
fun TrashCategoryCard(
category: Category,
noteCount: Int,
onRestore: () -> Unit,
onDeletePermanent: () -> Unit
) {
var showDeleteDialog by remember { mutableStateOf(false) }
// Dialog konfirmasi hapus permanen
if (showDeleteDialog) {
AlertDialog(
onDismissRequest = { showDeleteDialog = false },
title = { Text("Hapus Kategori Permanen?", color = Color.White) },
text = {
Text(
"Kategori '${category.name}' dan $noteCount catatan di dalamnya akan dihapus permanen. Tindakan ini tidak dapat dibatalkan!",
color = Color.White
)
},
confirmButton = {
Button(
onClick = {
onDeletePermanent()
showDeleteDialog = false
},
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFFEF4444)
)
) {
Text("Hapus Permanen", color = Color.White)
}
},
dismissButton = {
Button(
onClick = { showDeleteDialog = false },
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF64748B)
)
) {
Text("Batal", color = Color.White)
}
},
containerColor = Color(0xFF1E293B)
)
}
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(
containerColor = Color(0xFF1E293B)
),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) {
Column(modifier = Modifier.padding(16.dp)) {
// Header dengan gradient
Box(
modifier = Modifier
.fillMaxWidth()
.background(
brush = Brush.linearGradient(
colors = listOf(
Color(category.gradientStart).copy(alpha = 0.3f),
Color(category.gradientEnd).copy(alpha = 0.3f)
)
),
shape = RoundedCornerShape(12.dp)
)
.padding(16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.Folder,
contentDescription = null,
tint = Color.White.copy(0.9f),
modifier = Modifier.size(32.dp)
)
Spacer(modifier = Modifier.width(12.dp))
Column(modifier = Modifier.weight(1f)) {
Text(
category.name,
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.Bold,
color = Color.White
)
Spacer(modifier = Modifier.height(4.dp))
Text(
"$noteCount catatan",
style = MaterialTheme.typography.bodySmall,
color = Color.White.copy(0.8f)
)
}
}
}
Spacer(modifier = Modifier.height(12.dp))
// Info
Text(
"Kategori yang dihapus",
style = MaterialTheme.typography.bodySmall,
color = Color(0xFF64748B)
)
// Action buttons
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 12.dp),
horizontalArrangement = Arrangement.End
) {
TextButton(onClick = onRestore) {
Icon(
Icons.Default.Restore,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFF10B981)
)
Spacer(modifier = Modifier.width(4.dp))
Text("Pulihkan", color = Color(0xFF10B981), fontWeight = FontWeight.Bold)
}
Spacer(modifier = Modifier.width(8.dp))
TextButton(onClick = { showDeleteDialog = true }) {
Icon(
Icons.Default.Delete,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFFEF4444)
)
Spacer(modifier = Modifier.width(4.dp))
Text("Hapus Permanen", color = Color(0xFFEF4444), fontWeight = FontWeight.Bold)
}
}
}
}
}

View File

@ -1,129 +0,0 @@
package com.example.notesai.presentation.screens.trash.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
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 com.example.notesai.data.model.Note
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
// Helper function untuk extract plain text dari AnnotatedString JSON
private fun extractPlainText(jsonContent: String): String {
return try {
if (jsonContent.trim().startsWith("{")) {
val jsonElement = Json.parseToJsonElement(jsonContent)
val jsonObject = jsonElement.jsonObject
jsonObject["text"]?.jsonPrimitive?.content ?: ""
} else {
jsonContent
}
} catch (e: Exception) {
jsonContent
}
}
@Composable
fun TrashNoteCard(
note: Note,
categoryName: String,
onRestore: () -> Unit,
onDeletePermanent: () -> Unit
) {
val displayContent = if (note.description.isNotEmpty()) {
note.description
} else {
extractPlainText(note.content)
}
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(
containerColor = Color(0xFF7F1D1D).copy(0.2f)
),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) {
Column(modifier = Modifier.padding(16.dp)) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(modifier = Modifier.weight(1f)) {
Text(
note.title,
fontWeight = FontWeight.Bold,
color = Color.White,
style = MaterialTheme.typography.titleMedium
)
Spacer(modifier = Modifier.height(4.dp))
Text(
categoryName,
color = Color(0xFF64748B),
style = MaterialTheme.typography.bodySmall
)
}
}
if (displayContent.isNotEmpty()) {
Spacer(modifier = Modifier.height(8.dp))
Text(
displayContent,
maxLines = 2,
color = Color(0xFF94A3B8),
style = MaterialTheme.typography.bodyMedium
)
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 12.dp),
horizontalArrangement = Arrangement.End
) {
TextButton(onClick = onRestore) {
Icon(
Icons.Default.AccountBox,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFF10B981)
)
Spacer(modifier = Modifier.width(4.dp))
Text("Pulihkan", color = Color(0xFF10B981), fontWeight = FontWeight.Bold)
}
Spacer(modifier = Modifier.width(8.dp))
TextButton(onClick = onDeletePermanent) {
Icon(
Icons.Default.Delete,
contentDescription = null,
modifier = Modifier.size(18.dp),
tint = Color(0xFFEF4444)
)
Spacer(modifier = Modifier.width(4.dp))
Text("Hapus Permanen", color = Color(0xFFEF4444), fontWeight = FontWeight.Bold)
}
}
}
}
}

View File

@ -1,66 +0,0 @@
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
@Serializable
data class SpanDto(
val start: Int,
val end: Int,
val bold: Boolean = false,
val italic: Boolean = false,
val underline: Boolean = false
)
@Serializable
data class RichTextDto(
val text: String,
val spans: List<SpanDto>
)
object AnnotatedStringSerializer {
fun toJson(value: AnnotatedString): String {
val spans = value.spanStyles.map {
SpanDto(
start = it.start,
end = it.end,
bold = it.item.fontWeight != null,
italic = it.item.fontStyle != null,
underline = it.item.textDecoration != null
)
}
return Json.encodeToString(
RichTextDto(
text = value.text,
spans = spans
)
)
}
fun fromJson(json: String): AnnotatedString {
return try {
val dto = Json.decodeFromString<RichTextDto>(json)
val builder = AnnotatedString.Builder(dto.text)
dto.spans.forEach {
builder.addStyle(
SpanStyle(
fontWeight = if (it.bold) androidx.compose.ui.text.font.FontWeight.Bold else null,
fontStyle = if (it.italic) androidx.compose.ui.text.font.FontStyle.Italic else null,
textDecoration = if (it.underline) androidx.compose.ui.text.style.TextDecoration.Underline else null
),
it.start,
it.end
)
}
builder.toAnnotatedString()
} catch (e: Exception) {
AnnotatedString(json) // fallback plain
}
}
}

View File

@ -1,141 +0,0 @@
package com.example.notesai.util
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
object AppColors {
// Theme state
private var isDarkTheme by mutableStateOf(true)
// Primary Colors
val Primary: Color
get() = if (isDarkTheme) Color(0xFF6C63FF) else Color(0xFF5A52D5)
val Secondary: Color
get() = if (isDarkTheme) Color(0xFF03DAC6) else Color(0xFF018786)
val Accent: Color
get() = if (isDarkTheme) Color(0xFFFF6B9D) else Color(0xFFE91E63)
// Background Colors
val Background: Color
get() = if (isDarkTheme) Color(0xFF121212) else Color(0xFFFAFAFA)
val Surface: Color
get() = if (isDarkTheme) Color(0xFF1E1E1E) else Color(0xFFFFFFFF)
val SurfaceVariant: Color
get() = if (isDarkTheme) Color(0xFF2A2A2A) else Color(0xFFF5F5F5)
val SurfaceElevated: Color
get() = if (isDarkTheme) Color(0xFF252525) else Color(0xFFFFFFFF)
// Text Colors
val OnBackground: Color
get() = if (isDarkTheme) Color(0xFFE1E1E1) else Color(0xFF1C1B1F)
val OnSurface: Color
get() = if (isDarkTheme) Color(0xFFCCCCCC) else Color(0xFF1C1B1F)
val OnSurfaceVariant: Color
get() = if (isDarkTheme) Color(0xFF9E9E9E) else Color(0xFF49454F)
val OnSurfaceTertiary: Color
get() = if (isDarkTheme) Color(0xFF757575) else Color(0xFF79747E)
// Utility Colors
val Error: Color
get() = if (isDarkTheme) Color(0xFFCF6679) else Color(0xFFB3261E)
val Warning: Color
get() = if (isDarkTheme) Color(0xFFFFB74D) else Color(0xFFF57C00)
val Success: Color
get() = if (isDarkTheme) Color(0xFF81C784) else Color(0xFF388E3C)
val Info: Color
get() = if (isDarkTheme) Color(0xFF64B5F6) else Color(0xFF1976D2)
// Border & Divider
val Border: Color
get() = if (isDarkTheme) Color(0xFF3A3A3A) else Color(0xFFE0E0E0)
val Divider: Color
get() = if (isDarkTheme) Color(0xFF2E2E2E) else Color(0xFFE0E0E0)
// Function to update theme
fun setTheme(darkTheme: Boolean) {
isDarkTheme = darkTheme
}
// Get current theme state
fun isDark(): Boolean = isDarkTheme
}
object Constants {
// Animation Durations
const val ANIMATION_DURATION_SHORT = 150
const val ANIMATION_DURATION_MEDIUM = 300
const val ANIMATION_DURATION_LONG = 500
// Spacing values
object Spacing {
const val ExtraSmall = 4
const val Small = 8
const val Medium = 12
const val Large = 16
const val ExtraLarge = 24
const val ExtraExtraLarge = 32
}
// Border Radius values
object Radius {
const val Small = 8
const val Medium = 12
const val Large = 16
const val ExtraLarge = 24
const val ExtraExtraLarge = 32
}
// Elevation values
object Elevation {
const val None = 0
const val Small = 2
const val Medium = 4
const val Large = 8
const val ExtraLarge = 12
}
// Reference to AppColors for compatibility
val AppColors = com.example.notesai.util.AppColors
// Category gradient colors - 8 pilihan warna
val CategoryColors = listOf(
// Purple gradient
0xFF6750A4L to 0xFF7E57C2L,
// Pink gradient
0xFF9C27B0L to 0xFFE91E63L,
// Blue gradient
0xFF2196F3L to 0xFF03A9F4L,
// Green gradient
0xFF4CAF50L to 0xFF8BC34AL,
// Orange gradient
0xFFFF9800L to 0xFFFFB74DL,
// Red gradient
0xFFF44336L to 0xFFE91E63L,
// Teal gradient
0xFF009688L to 0xFF26A69AL,
// Indigo gradient
0xFF3F51B5L to 0xFF5C6BC0L
)
}

View File

@ -1,42 +0,0 @@
// File: util/DateFormatter.kt
package com.example.notesai.util
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
object DateFormatter {
private val shortFormat = SimpleDateFormat("dd MMM, HH:mm", Locale("id", "ID"))
private val longFormat = SimpleDateFormat("dd MMMM yyyy, HH:mm", Locale("id", "ID"))
private val timeOnlyFormat = SimpleDateFormat("HH:mm", Locale("id", "ID"))
private val dateOnlyFormat = SimpleDateFormat("dd MMM yyyy", Locale("id", "ID"))
fun formatShort(timestamp: Long): String {
return shortFormat.format(Date(timestamp))
}
fun formatLong(timestamp: Long): String {
return longFormat.format(Date(timestamp))
}
fun formatTimeOnly(timestamp: Long): String {
return timeOnlyFormat.format(Date(timestamp))
}
fun formatDateOnly(timestamp: Long): String {
return dateOnlyFormat.format(Date(timestamp))
}
fun formatRelative(timestamp: Long): String {
val now = System.currentTimeMillis()
val diff = now - timestamp
return when {
diff < 60000 -> "Baru saja"
diff < 3600000 -> "${diff / 60000} menit yang lalu"
diff < 86400000 -> "${diff / 3600000} jam yang lalu"
diff < 604800000 -> "${diff / 86400000} hari yang lalu"
else -> formatDateOnly(timestamp)
}
}
}

View File

@ -1,31 +0,0 @@
// File: util/Extensions.kt
package com.example.notesai.util
import androidx.compose.ui.graphics.Color
// String Extensions
fun String.truncate(maxLength: Int, suffix: String = "..."): String {
return if (this.length > maxLength) {
this.substring(0, maxLength) + suffix
} else {
this
}
}
// Color Extensions
fun Long.toColor(): Color = Color(this)
fun Color.withAlpha(alpha: Float): Color = this.copy(alpha = alpha)
// List Extensions
fun <T> List<T>.replaceWhere(predicate: (T) -> Boolean, transform: (T) -> T): List<T> {
return this.map { if (predicate(it)) transform(it) else it }
}
fun <T> List<T>.removeWhere(predicate: (T) -> Boolean): List<T> {
return this.filter { !predicate(it) }
}
fun <T> List<T>.updateWhere(predicate: (T) -> Boolean, transform: (T) -> T): List<T> {
return this.map { if (predicate(it)) transform(it) else it }
}

View File

@ -1,221 +0,0 @@
package com.example.notesai.util
import android.content.Context
import android.net.Uri
import android.util.Log
import com.tom_roush.pdfbox.android.PDFBoxResourceLoader
import com.tom_roush.pdfbox.pdmodel.PDDocument
import com.tom_roush.pdfbox.text.PDFTextStripper
import java.io.BufferedReader
import java.io.InputStreamReader
object FileParser {
private const val TAG = "FileParser"
/**
* Initialize PDFBox (call this in Application.onCreate or before first use)
*/
fun initPDFBox(context: Context) {
try {
PDFBoxResourceLoader.init(context)
Log.d(TAG, "PDFBox initialized successfully")
} catch (e: Exception) {
Log.e(TAG, "Failed to initialize PDFBox", e)
}
}
/**
* Parse file berdasarkan tipe
*/
suspend fun parseFile(context: Context, uri: Uri): FileParseResult {
return try {
val mimeType = context.contentResolver.getType(uri)
val fileName = getFileName(context, uri)
Log.d(TAG, "Parsing file: $fileName, type: $mimeType")
val content = when {
mimeType == "application/pdf" || fileName.endsWith(".pdf", ignoreCase = true) -> {
parsePDF(context, uri)
}
mimeType == "text/plain" || fileName.endsWith(".txt", ignoreCase = true) -> {
parseTXT(context, uri)
}
mimeType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|| fileName.endsWith(".docx", ignoreCase = true) -> {
parseDOCX(context, uri)
}
else -> {
return FileParseResult.Error("Format file tidak didukung: $mimeType")
}
}
if (content.isBlank()) {
FileParseResult.Error("File kosong atau tidak dapat dibaca")
} else {
FileParseResult.Success(
content = content,
fileName = fileName,
fileType = getFileType(fileName),
wordCount = content.split(Regex("\\s+")).size
)
}
} catch (e: Exception) {
Log.e(TAG, "Error parsing file", e)
FileParseResult.Error("Gagal membaca file: ${e.message}")
}
}
/**
* Parse PDF file
*/
private fun parsePDF(context: Context, uri: Uri): String {
val inputStream = context.contentResolver.openInputStream(uri)
?: throw Exception("Cannot open file")
return inputStream.use { stream ->
val document = PDDocument.load(stream)
val stripper = PDFTextStripper()
val text = stripper.getText(document)
document.close()
text.trim()
}
}
/**
* Parse TXT file
*/
private fun parseTXT(context: Context, uri: Uri): String {
val inputStream = context.contentResolver.openInputStream(uri)
?: throw Exception("Cannot open file")
return inputStream.use { stream ->
BufferedReader(InputStreamReader(stream, Charsets.UTF_8))
.readText()
.trim()
}
}
/**
* Parse DOCX file - SIMPLIFIED VERSION
* Hanya extract text mentah dari XML
*/
private fun parseDOCX(context: Context, uri: Uri): String {
val inputStream = context.contentResolver.openInputStream(uri)
?: throw Exception("Cannot open file")
return inputStream.use { stream ->
try {
// DOCX adalah ZIP file, kita extract document.xml
val zipInputStream = java.util.zip.ZipInputStream(stream)
val text = StringBuilder()
var entry = zipInputStream.nextEntry
while (entry != null) {
if (entry.name == "word/document.xml") {
val xmlContent = zipInputStream.bufferedReader().readText()
// Extract text dari XML tags
// Format: <w:t>text here</w:t>
val textPattern = Regex("<w:t[^>]*>([^<]+)</w:t>")
textPattern.findAll(xmlContent).forEach { match ->
text.append(match.groupValues[1])
text.append(" ")
}
// Extract text dari paragraph tags
val paraPattern = Regex("<w:p[^>]*>(.*?)</w:p>", RegexOption.DOT_MATCHES_ALL)
paraPattern.findAll(xmlContent).forEach { match ->
val paraContent = match.groupValues[1]
val textInPara = Regex("<w:t[^>]*>([^<]+)</w:t>")
textInPara.findAll(paraContent).forEach { textMatch ->
text.append(textMatch.groupValues[1])
text.append(" ")
}
text.append("\n")
}
break
}
entry = zipInputStream.nextEntry
}
zipInputStream.close()
text.toString().trim()
} catch (e: Exception) {
Log.e(TAG, "Error parsing DOCX", e)
throw Exception("Gagal membaca file DOCX: ${e.message}")
}
}
}
/**
* Get file name from URI
*/
private fun getFileName(context: Context, uri: Uri): String {
var fileName = "unknown"
context.contentResolver.query(uri, null, null, null, null)?.use { cursor ->
val nameIndex = cursor.getColumnIndex(android.provider.OpenableColumns.DISPLAY_NAME)
if (cursor.moveToFirst() && nameIndex != -1) {
fileName = cursor.getString(nameIndex)
}
}
return fileName
}
/**
* Get file type display name
*/
private fun getFileType(fileName: String): String {
return when {
fileName.endsWith(".pdf", ignoreCase = true) -> "PDF"
fileName.endsWith(".txt", ignoreCase = true) -> "Text"
fileName.endsWith(".docx", ignoreCase = true) -> "Word"
else -> "Unknown"
}
}
/**
* Get file size
*/
fun getFileSize(context: Context, uri: Uri): Long {
var size = 0L
context.contentResolver.query(uri, null, null, null, null)?.use { cursor ->
val sizeIndex = cursor.getColumnIndex(android.provider.OpenableColumns.SIZE)
if (cursor.moveToFirst() && sizeIndex != -1) {
size = cursor.getLong(sizeIndex)
}
}
return size
}
/**
* Format file size untuk display
*/
fun formatFileSize(bytes: Long): String {
return when {
bytes < 1024 -> "$bytes B"
bytes < 1024 * 1024 -> "${bytes / 1024} KB"
else -> "${bytes / (1024 * 1024)} MB"
}
}
}
/**
* Result dari parsing file
*/
sealed class FileParseResult {
data class Success(
val content: String,
val fileName: String,
val fileType: String,
val wordCount: Int
) : FileParseResult()
data class Error(val message: String) : FileParseResult()
}

View File

@ -1,68 +0,0 @@
package com.example.notesai.util
/**
* Utility untuk convert markdown text ke plain text
*/
object MarkdownStripper {
/**
* Strip semua markdown formatting dan return plain text
*/
fun stripMarkdown(text: String): String {
var result = text
// 1. Remove code blocks (```...```)
result = result.replace(Regex("""```[\s\S]*?```"""), "")
// 2. Remove inline code (`...`)
result = result.replace(Regex("""`([^`]+)`"""), "$1")
// 3. Remove bold (**...**)
result = result.replace(Regex("""\*\*([^*]+)\*\*"""), "$1")
// 4. Remove italic (*...*)
result = result.replace(Regex("""\*([^*]+)\*"""), "$1")
// 5. Remove strikethrough (~~...~~)
result = result.replace(Regex("""~~([^~]+)~~"""), "$1")
// 6. Remove headers (# ## ### etc)
result = result.replace(Regex("""^#{1,6}\s+""", RegexOption.MULTILINE), "")
// 7. Remove links [text](url) → text
result = result.replace(Regex("""\[([^\]]+)\]\([^)]+\)"""), "$1")
// 8. Remove images ![alt](url) → alt
result = result.replace(Regex("""!\[([^\]]*)\]\([^)]+\)"""), "$1")
// 9. Remove horizontal rules (---, ***, ___)
result = result.replace(Regex("""^[-*_]{3,}$""", RegexOption.MULTILINE), "")
// 10. Remove blockquotes (> ...)
result = result.replace(Regex("""^>\s+""", RegexOption.MULTILINE), "")
// 11. Remove unordered list markers (-, *, +)
result = result.replace(Regex("""^[\s]*[-*+]\s+""", RegexOption.MULTILINE), "")
// 12. Remove ordered list markers (1. 2. 3.)
result = result.replace(Regex("""^[\s]*\d+\.\s+""", RegexOption.MULTILINE), "")
// 13. Clean up extra whitespace
result = result.replace(Regex("""\n{3,}"""), "\n\n") // Max 2 consecutive newlines
result = result.trim()
return result
}
/**
* Get preview text (first N characters, stripped)
*/
fun getPlainPreview(text: String, maxLength: Int = 100): String {
val plain = stripMarkdown(text)
return if (plain.length > maxLength) {
plain.take(maxLength).trim() + "..."
} else {
plain
}
}
}

View File

@ -1,289 +0,0 @@
package com.example.notesai.util
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.*
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.notesai.util.AppColors
import com.example.notesai.util.Constants
@Composable
fun MarkdownText(
markdown: String,
modifier: Modifier = Modifier
) {
Column(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
parseMarkdown(markdown).forEach { block ->
when (block) {
is MarkdownBlock.Paragraph -> {
Text(
text = buildAnnotatedString {
appendInlineMarkdown(block.content)
},
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurface,
lineHeight = 24.sp
)
}
is MarkdownBlock.Header -> {
Spacer(modifier = Modifier.height(4.dp))
Text(
text = block.content,
style = when (block.level) {
1 -> MaterialTheme.typography.headlineLarge
2 -> MaterialTheme.typography.headlineMedium
3 -> MaterialTheme.typography.headlineSmall
else -> MaterialTheme.typography.titleLarge
},
color = AppColors.OnBackground,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(4.dp))
}
is MarkdownBlock.CodeBlock -> {
Surface(
modifier = Modifier.fillMaxWidth(),
color = AppColors.SurfaceVariant,
shape = RoundedCornerShape(Constants.Radius.Medium.dp)
) {
Text(
text = block.content,
modifier = Modifier.padding(12.dp),
fontFamily = FontFamily.Monospace,
style = MaterialTheme.typography.bodySmall,
color = AppColors.OnSurface,
fontSize = 13.sp
)
}
}
is MarkdownBlock.ListItem -> {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
text = if (block.isOrdered) "${block.number}." else "",
color = AppColors.Primary,
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.width(20.dp)
)
Text(
text = buildAnnotatedString {
appendInlineMarkdown(block.content)
},
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurface,
modifier = Modifier.weight(1f)
)
}
}
is MarkdownBlock.Quote -> {
Surface(
modifier = Modifier.fillMaxWidth(),
color = AppColors.Primary.copy(alpha = 0.1f),
shape = RoundedCornerShape(Constants.Radius.Medium.dp)
) {
Row {
Spacer(
modifier = Modifier
.width(4.dp)
.fillMaxHeight()
.background(AppColors.Primary)
)
Text(
text = buildAnnotatedString {
appendInlineMarkdown(block.content)
},
modifier = Modifier.padding(12.dp),
style = MaterialTheme.typography.bodyMedium,
color = AppColors.OnSurface,
fontStyle = FontStyle.Italic
)
}
}
}
}
}
}
}
// Markdown Block Types
sealed class MarkdownBlock {
data class Paragraph(val content: String) : MarkdownBlock()
data class Header(val level: Int, val content: String) : MarkdownBlock()
data class CodeBlock(val content: String, val language: String? = null) : MarkdownBlock()
data class ListItem(val content: String, val isOrdered: Boolean, val number: Int = 0) : MarkdownBlock()
data class Quote(val content: String) : MarkdownBlock()
}
// Parse markdown into blocks
fun parseMarkdown(text: String): List<MarkdownBlock> {
val blocks = mutableListOf<MarkdownBlock>()
val lines = text.lines()
var i = 0
while (i < lines.size) {
val line = lines[i]
when {
// Code block
line.trimStart().startsWith("```") -> {
val language = line.trimStart().removePrefix("```").trim()
val codeLines = mutableListOf<String>()
i++
while (i < lines.size && !lines[i].trimStart().startsWith("```")) {
codeLines.add(lines[i])
i++
}
blocks.add(MarkdownBlock.CodeBlock(codeLines.joinToString("\n"), language.ifEmpty { null }))
i++
}
// Header
line.trimStart().startsWith("#") -> {
val level = line.takeWhile { it == '#' }.length
val content = line.removePrefix("#".repeat(level)).trim()
blocks.add(MarkdownBlock.Header(level, content))
i++
}
// Quote
line.trimStart().startsWith(">") -> {
val content = line.trimStart().removePrefix(">").trim()
blocks.add(MarkdownBlock.Quote(content))
i++
}
// Unordered list
line.trimStart().matches(Regex("^[-*+]\\s+.*")) -> {
val content = line.trimStart().replaceFirst(Regex("^[-*+]\\s+"), "")
blocks.add(MarkdownBlock.ListItem(content, false))
i++
}
// Ordered list
line.trimStart().matches(Regex("^\\d+\\.\\s+.*")) -> {
val number = line.trimStart().takeWhile { it.isDigit() }.toIntOrNull() ?: 1
val content = line.trimStart().replaceFirst(Regex("^\\d+\\.\\s+"), "")
blocks.add(MarkdownBlock.ListItem(content, true, number))
i++
}
// Empty line - skip
line.isBlank() -> {
i++
}
// Paragraph
else -> {
val paragraphLines = mutableListOf<String>()
while (i < lines.size && lines[i].isNotBlank() &&
!lines[i].trimStart().startsWith("#") &&
!lines[i].trimStart().startsWith(">") &&
!lines[i].trimStart().startsWith("```") &&
!lines[i].trimStart().matches(Regex("^[-*+]\\s+.*")) &&
!lines[i].trimStart().matches(Regex("^\\d+\\.\\s+.*"))) {
paragraphLines.add(lines[i])
i++
}
if (paragraphLines.isNotEmpty()) {
blocks.add(MarkdownBlock.Paragraph(paragraphLines.joinToString(" ")))
}
}
}
}
return blocks
}
// Parse inline markdown (bold, italic, code, links)
fun AnnotatedString.Builder.appendInlineMarkdown(text: String) {
var currentIndex = 0
val inlinePatterns = listOf(
// Bold with **
Regex("""\*\*(.+?)\*\*""") to { content: String ->
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
append(content)
}
},
// Bold with __
Regex("""__(.+?)__""") to { content: String ->
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
append(content)
}
},
// Italic with *
Regex("""\*(.+?)\*""") to { content: String ->
withStyle(SpanStyle(fontStyle = FontStyle.Italic)) {
append(content)
}
},
// Italic with _
Regex("""_(.+?)_""") to { content: String ->
withStyle(SpanStyle(fontStyle = FontStyle.Italic)) {
append(content)
}
},
// Inline code
Regex("""`(.+?)`""") to { content: String ->
withStyle(
SpanStyle(
fontFamily = FontFamily.Monospace,
background = Color(0xFF1E1E1E),
color = Color(0xFFE5E5E5)
)
) {
append(" $content ")
}
},
// Links [text](url)
Regex("""\[(.+?)]\((.+?)\)""") to { content: String ->
withStyle(
SpanStyle(
color = Color(0xFF3B82F6),
textDecoration = TextDecoration.Underline
)
) {
append(content)
}
}
)
var remainingText = text
val matches = mutableListOf<Triple<Int, Int, (String) -> Unit>>()
// Find all matches
inlinePatterns.forEach { (regex, styleApplier) ->
regex.findAll(remainingText).forEach { match ->
val content = match.groupValues[1]
matches.add(Triple(match.range.first, match.range.last + 1) { styleApplier(content) })
}
}
// Sort matches by start position
val sortedMatches = matches.sortedBy { it.first }
// Apply styles
var lastIndex = 0
sortedMatches.forEach { (start, end, applier) ->
if (start >= lastIndex) {
// Append text before match
append(remainingText.substring(lastIndex, start))
// Apply style
applier("")
lastIndex = end
}
}
// Append remaining text
if (lastIndex < remainingText.length) {
append(remainingText.substring(lastIndex))
}
}

View File

@ -1,9 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="108dp"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:viewportHeight="24"
android:viewportWidth="24">
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:pathData="M22,10.5V19c0,1.1 -0.9,2 -2,2H4c-1.1,0 -2,-0.9 -2,-2V5c0,-1.1 0.9,-2 2,-2h9.5L22,10.5z M15,5h2v5h5v2l-7,-7z"/>
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@ -1,3 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Notesai" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>
</resources>

View File

@ -1,2 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View File

@ -1,3 +1,3 @@
<resources>
<string name="app_name">NotesAI</string>
<string name="app_name">AI Notes</string>
</resources>

View File

@ -1,5 +1,10 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.NotesAI" parent="android:Theme.Material.Light.NoActionBar" />
<!-- Base application theme. -->
<style name="Base.Theme.Notesai" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>
<style name="Theme.Notesai" parent="Base.Theme.Notesai" />
</resources>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

View File

@ -1,5 +1,5 @@
[versions]
agp = "8.13.2"
agp = "8.13.1"
kotlin = "2.0.21"
coreKtx = "1.10.1"
junit = "4.13.2"
@ -9,16 +9,6 @@ appcompat = "1.6.1"
material = "1.10.0"
activity = "1.8.0"
constraintlayout = "2.1.4"
uiText = "1.10.0"
material3 = "1.4.0"
animationCore = "1.10.0"
firebaseAnnotations = "17.0.0"
firebaseFirestoreKtx = "26.0.2"
uiGraphics = "1.10.0"
roomCompiler = "2.8.4"
glance = "1.1.1"
animation = "1.10.0"
junitKtx = "1.3.0"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@ -29,16 +19,6 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
androidx-ui-text = { group = "androidx.compose.ui", name = "ui-text", version.ref = "uiText" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
androidx-animation-core = { group = "androidx.compose.animation", name = "animation-core", version.ref = "animationCore" }
firebase-annotations = { group = "com.google.firebase", name = "firebase-annotations", version.ref = "firebaseAnnotations" }
firebase-firestore-ktx = { group = "com.google.firebase", name = "firebase-firestore-ktx", version.ref = "firebaseFirestoreKtx" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics", version.ref = "uiGraphics" }
androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "roomCompiler" }
androidx-glance = { group = "androidx.glance", name = "glance", version.ref = "glance" }
androidx-animation = { group = "androidx.compose.animation", name = "animation", version.ref = "animation" }
androidx-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junitKtx" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }