-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for AI chat and fixed error when clicking to view…
… file properties.
- Loading branch information
Showing
72 changed files
with
2,603 additions
and
1,980 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/etb/filemanager/compose/core/extensions/MessageExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - MessageExt.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.extensions | ||
|
||
import com.etb.filemanager.compose.core.models.Message | ||
import com.etb.filemanager.compose.core.models.Participant | ||
import com.google.ai.client.generativeai.type.Content | ||
import com.google.ai.client.generativeai.type.content | ||
|
||
fun List<Message>.hasPendingMessage(): Boolean = any { it.isPending } | ||
|
||
fun List<Message>.toContent(): List<Content> { | ||
val filteredList = filter { !it.isPending && it.participant != Participant.ERROR && it.participant != Participant.USER_ERROR } | ||
|
||
return filteredList.map { msg -> | ||
val role = if (msg.participant == Participant.USER) "user" else "model" | ||
content(role = role) { | ||
text(msg.text) | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/etb/filemanager/compose/core/models/Chat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - ChatUtils.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.models | ||
|
||
data class Chat( | ||
val id: Int = 0, | ||
val chatSettings: ChatSettings = ChatSettings(), | ||
val messages: List<Message> = emptyList(), | ||
) |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/etb/filemanager/compose/core/models/ChatSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - ChatSettings.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.models | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ChatSettings( | ||
val title: String = "ChatSphere" | ||
) |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/etb/filemanager/compose/core/models/FileOperationItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - FileOperationItem.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.models | ||
|
||
data class FileOperationItem( | ||
val title: String, | ||
val content: String | ||
) |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/etb/filemanager/compose/core/models/FileOperationResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - FileOperationResult.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.models | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class FileOperationResult(val name: String, val desc: String, val result: OperationResult) | ||
|
||
enum class OperationResult(val value: String){ | ||
SUCCESS("Success"), | ||
FAILED("Failed") | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/etb/filemanager/compose/core/models/Message.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - Message.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.models | ||
|
||
import android.net.Uri | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
enum class Participant { | ||
USER, | ||
MODEL, | ||
ERROR, | ||
USER_ERROR | ||
} | ||
|
||
@Serializable | ||
data class Message( | ||
val id: Int = 0 , | ||
val text: String = "", | ||
val participant: Participant = Participant.MODEL, | ||
val isPending: Boolean = false, | ||
val operationResults: List<FileOperationResult> = emptyList() | ||
){ | ||
override fun toString(): String { | ||
return "id: $id\ntext: $text\nparticipant: $participant\nisPending: $isPending" | ||
} | ||
} | ||
|
||
object UriSerializer : KSerializer<Uri> { | ||
override val descriptor: SerialDescriptor | ||
get() = PrimitiveSerialDescriptor("Uri", PrimitiveKind.STRING) | ||
|
||
override fun deserialize(decoder: Decoder): Uri { | ||
return Uri.parse(decoder.decodeString()) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: Uri) { | ||
encoder.encodeString(value.toString()) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/etb/filemanager/compose/core/navigation/CategoryGraphNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - CategoryGraphNavigation.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.navigation | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavOptions | ||
import androidx.navigation.navigation | ||
import com.etb.filemanager.manager.category.adapter.CategoryFileModel | ||
|
||
const val CategoryGraphPattern = "category" | ||
|
||
fun NavController.navigateToCategoryGraph(navOptions: NavOptions? = null) { | ||
navigate(CategoryGraphPattern, navOptions) | ||
} | ||
|
||
fun NavGraphBuilder.categoryGraph( | ||
navController: NavController, | ||
paddingValues: PaddingValues, | ||
categoryFileModel: CategoryFileModel? | ||
) { | ||
navigation( | ||
startDestination = CategoryListRoute, route = CategoryGraphPattern | ||
) { | ||
categoryListScreen( | ||
paddingValues = paddingValues, | ||
categoryFileModel = categoryFileModel, | ||
onNavigateToMediaView = { | ||
navController.navigateToMediaView(it) | ||
} | ||
) | ||
|
||
mediaViewScreen( | ||
paddingValues = paddingValues | ||
) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/etb/filemanager/compose/core/navigation/CategoryListNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - CategoryListNavigation.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.navigation | ||
|
||
import android.os.Bundle | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavOptions | ||
import androidx.navigation.compose.composable | ||
import com.etb.filemanager.compose.feature.presentation.categorylist.components.CategoryListScreen | ||
import com.etb.filemanager.manager.category.adapter.CategoryFileModel | ||
|
||
const val CategoryListRoute = "category_list" | ||
|
||
fun NavGraphBuilder.categoryListScreen( | ||
paddingValues: PaddingValues, | ||
categoryFileModel: CategoryFileModel?, | ||
onNavigateToMediaView: (Bundle) -> Unit | ||
){ | ||
composable(CategoryListRoute){ | ||
|
||
CategoryListScreen( | ||
innerPadding = paddingValues, | ||
categoryFileModel = categoryFileModel, | ||
navigate = {_, args -> | ||
onNavigateToMediaView(args) | ||
}) | ||
} | ||
} | ||
|
||
fun NavController.navigateToCategoryList(navOptions: NavOptions? = null){ | ||
navigate(CategoryListRoute, navOptions) | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/etb/filemanager/compose/core/navigation/ChatNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 Juan Nascimento | ||
* Part of FileManagerSphere - ChatNavigation.kt | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* More details at: https://www.gnu.org/licenses/ | ||
*/ | ||
|
||
package com.etb.filemanager.compose.core.navigation | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.runtime.getValue | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavOptions | ||
import androidx.navigation.compose.composable | ||
import com.etb.filemanager.compose.feature.presentation.chat_screen.ChatScreen | ||
import com.etb.filemanager.compose.feature.presentation.chat_screen.ChatViewModel | ||
|
||
const val ChatRoute = "chat" | ||
|
||
fun NavGraphBuilder.chatScreen( | ||
paddingValues: PaddingValues | ||
) { | ||
composable( | ||
route = ChatRoute | ||
) { | ||
val viewModel: ChatViewModel = hiltViewModel() | ||
val uiState by viewModel.state.collectAsStateWithLifecycle() | ||
|
||
ChatScreen(uiState = uiState, | ||
paddingValues = paddingValues, | ||
onClickSendMsg = { msg -> | ||
viewModel.sendMessage(msg) | ||
}, | ||
onClickChat = { viewModel.setCurrentChat(it) }) { viewModel.newChat() } | ||
} | ||
} | ||
|
||
fun NavController.navigateToChat(navOptions: NavOptions? = null) { | ||
navigate(ChatRoute, navOptions) | ||
} |
Oops, something went wrong.