Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groups are now shown in each group #58

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ import kotlinx.coroutines.flow.Flow
@Dao
interface DocumentsDao {

@Transaction
@Query(
"""
SELECT * FROM document_table
WHERE groupId=:groupId AND isCreated=1
ORDER BY createdDate
"""
)
suspend fun getDocumentsByGroupId(groupId: Long): List<FullDocumentEntity>

@[Transaction Query("SELECT * FROM document_table WHERE isCreated=1 ORDER BY createdDate")]
fun getFullDocumentsFlow(): Flow<List<FullDocumentEntity>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ interface DocumentRepository {
suspend fun updateDocumentWithFiles(document: Document, files: List<DocumentFile>)

suspend fun updateFilesInDocument(documentId: Long, files: List<DocumentFile>)
suspend fun getDocumentsByGroupId(groupId: Long): List<Document>
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
documentsDao.insert(documentMapper.toDocumentEntity(document))
}

override suspend fun addDocuments(documents: List<Document>) = withContext(ioDispatcher) {
override suspend fun addDocuments(documents: List<Document>): Unit = withContext(ioDispatcher) {

Check warning on line 85 in feature/docs/repo-impl/src/main/java/com/grappim/docuvault/feature/docs/repoimpl/DocumentRepositoryImpl.kt

View check run for this annotation

Codecov / codecov/patch

feature/docs/repo-impl/src/main/java/com/grappim/docuvault/feature/docs/repoimpl/DocumentRepositoryImpl.kt#L85

Added line #L85 was not covered by tests
documents.map { document ->
async {
documentsDao.insertDocumentAndFiles(
Expand All @@ -94,7 +94,6 @@
)
}
}.awaitAll()
Unit
}

override suspend fun removeDocumentById(id: Long) {
Expand All @@ -114,4 +113,9 @@
val filesEntities = documentFileMapper.toDocumentFileEntityList(documentId, files)
documentsDao.upsertFiles(filesEntities)
}

override suspend fun getDocumentsByGroupId(groupId: Long): List<Document> {
val entities = documentsDao.getDocumentsByGroupId(groupId)
return documentMapper.toDocumentList(entities)

Check warning on line 119 in feature/docs/repo-impl/src/main/java/com/grappim/docuvault/feature/docs/repoimpl/DocumentRepositoryImpl.kt

View check run for this annotation

Codecov / codecov/patch

feature/docs/repo-impl/src/main/java/com/grappim/docuvault/feature/docs/repoimpl/DocumentRepositoryImpl.kt#L117-L119

Added lines #L117 - L119 were not covered by tests
}
}
3 changes: 3 additions & 0 deletions feature/group/details/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ android {
dependencies {
implementation(project(":uikit"))
implementation(project(":core:navigation"))
implementation(project(":utils:files"))
implementation(project(":feature:group:domain"))
implementation(project(":feature:group:repo-api"))
implementation(project(":feature:docs:repo-api"))

implementation(libs.androidx.core.ktx)

Expand All @@ -28,4 +30,5 @@ dependencies {
implementation(libs.androidx.hilt.navigation.compose)

implementation(libs.compose.color.picker.android)
implementation(libs.coil)
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,85 @@
package com.grappim.docuvault.feature.group.details

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.compose.rememberAsyncImagePainter
import com.grappim.docuvault.uikit.theme.DefaultArrangement
import com.grappim.docuvault.uikit.theme.DefaultHorizontalPadding
import com.grappim.docuvault.uikit.widget.PlatoImage

@Composable
@Suppress("UnusedParameter")
fun GroupDetailsRoute(viewModel: GroupDetailsViewModel = hiltViewModel(), goBack: () -> Unit) {
fun GroupDetailsRoute(
viewModel: GroupDetailsViewModel = hiltViewModel(),
onDocumentClick: (id: Long) -> Unit
) {
val state by viewModel.viewState.collectAsStateWithLifecycle()
GroupDetailsContent(state = state)
if (state.group != null) {
GroupDetailsContent(state = state, onDocumentClick = onDocumentClick)
}
}

@Composable
private fun GroupDetailsContent(state: GroupDetailsState) {
if (state.group != null) {
Text(text = state.group.name)
private fun GroupDetailsContent(state: GroupDetailsState, onDocumentClick: (id: Long) -> Unit) {
requireNotNull(state.group)

LazyColumn(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = DefaultHorizontalPadding),
verticalArrangement = Arrangement.spacedBy(DefaultArrangement),
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
Text(text = state.group.name)
}
items(state.documents) { document ->
Card(
modifier = Modifier
.fillMaxWidth(),
backgroundColor = document.groupColor,
onClick = {
onDocumentClick(document.id.toLong())
}
) {
Column(
modifier = Modifier
.padding(horizontal = 8.dp)
) {
Text(
text = document.name,
modifier = Modifier
.padding(
top = 8.dp
)
)
Text(text = document.createdDate)

Card(
modifier = Modifier
.padding(
top = 8.dp,
bottom = 8.dp
)
.size(100.dp)
) {
PlatoImage(painter = rememberAsyncImagePainter(document.preview))
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.grappim.docuvault.feature.group.details

import com.grappim.docuvault.feature.group.domain.Group
import com.grappim.docuvault.utils.files.models.DocumentListUI

data class GroupDetailsState(
val group: Group? = null
val group: Group? = null,
val documents: List<DocumentListUI> = emptyList()

Check warning on line 8 in feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsState.kt

View check run for this annotation

Codecov / codecov/patch

feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsState.kt#L7-L8

Added lines #L7 - L8 were not covered by tests
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.grappim.docuvault.core.navigation.GroupNavDestinations
import com.grappim.docuvault.feature.docs.repoapi.DocumentRepository
import com.grappim.docuvault.feature.group.repoapi.GroupRepository
import com.grappim.docuvault.utils.files.mappers.DocsListUIMapper
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand All @@ -15,7 +17,9 @@
@HiltViewModel
class GroupDetailsViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle,
private val groupRepository: GroupRepository
private val groupRepository: GroupRepository,
private val docRepository: DocumentRepository,
private val docsListUIMapper: DocsListUIMapper

Check warning on line 22 in feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt

View check run for this annotation

Codecov / codecov/patch

feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt#L20-L22

Added lines #L20 - L22 were not covered by tests
) : ViewModel() {

private val _viewState = MutableStateFlow(GroupDetailsState())
Expand All @@ -26,14 +30,16 @@
get() = requireNotNull(savedStateHandle[GroupNavDestinations.GroupDetails.KEY_GROUP_ID])

init {
fetchGroup()
getData()

Check warning on line 33 in feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt

View check run for this annotation

Codecov / codecov/patch

feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt#L33

Added line #L33 was not covered by tests
}

private fun fetchGroup() {
private fun getData() {
viewModelScope.launch {
val group = groupRepository.getGroupById(groupId)
val documents = docRepository.getDocumentsByGroupId(groupId.toLong())
val uiDocuments = docsListUIMapper.toDocumentListUIList(documents)

Check warning on line 40 in feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt

View check run for this annotation

Codecov / codecov/patch

feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt#L39-L40

Added lines #L39 - L40 were not covered by tests
_viewState.update {
it.copy(group = group)
it.copy(group = group, documents = uiDocuments)

Check warning on line 42 in feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt

View check run for this annotation

Codecov / codecov/patch

feature/group/details/src/main/java/com/grappim/docuvault/feature/group/details/GroupDetailsViewModel.kt#L42

Added line #L42 was not covered by tests
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.grappim.docuvault.core.navigation.DocumentsNavDestinations
import com.grappim.docuvault.core.navigation.GroupNavDestinations
import com.grappim.docuvault.core.navigation.MainNavDestinations
import com.grappim.docuvault.feature.group.details.GroupDetailsRoute
Expand Down Expand Up @@ -43,9 +44,14 @@ fun NavGraphBuilder.groupsScreens(navController: NavController) {
)
) {
GroupDetailsRoute(
goBack = {
navController.popBackStack()
onDocumentClick = { id ->
navController.navigate(
DocumentsNavDestinations.Details.createRoute(id)
)
}
// goBack = {
// navController.popBackStack()
// }
)
}
}
Loading