Skip to content

Commit

Permalink
Make app sync with DB (#4)
Browse files Browse the repository at this point in the history
* add: Passing BoardId btw navGraphs

* fix: Update Card details functionality

* add: Dialog for updating the List title.

* fix: Create Card Flow with selected boardId and Listid

* random Images Cover for boards.
  • Loading branch information
nikeight authored Aug 25, 2024
1 parent 037b32b commit 4cfdbb4
Show file tree
Hide file tree
Showing 54 changed files with 997 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ fun JtbNavHost(
) {
dashboardGraph(
isExpandedScreen = isExpandedScreen,
navigateToTaskBoard = {
navigateToTaskBoard = { boardId ->
onNavigateToDestination(
TaskBoardDestination,
TaskBoardDestination.route
TaskBoardDestination.route + "/$boardId"
)
},
navigateToCreateCard = {
Expand All @@ -77,10 +77,10 @@ fun JtbNavHost(
taskBoardGraph(
isExpandedScreen = isExpandedScreen,
onBackClick = onBackClick,
navigateToCreateCard = {
navigateToCreateCard = { boardId, listId, cardId ->
onNavigateToDestination(
CardDetailsDestination,
CardDetailsDestination.route
CardDetailsDestination.route + "/$boardId" + "/$listId" + "/$cardId"
)
},
navigateToChangeBackgroundScreen = {
Expand All @@ -98,10 +98,13 @@ fun JtbNavHost(

createBoardGraph(
onBackClick = onBackClick,
navigateToBoardRoute = {
navigateToBoardRoute = { passedId ->
// Clear the Create Board Screen then only
// Navigate to the TaskBoard Screen
navController.popBackStack()
onNavigateToDestination(
TaskBoardDestination,
TaskBoardDestination.route,
TaskBoardDestination.route + "/$passedId",
)
}
)
Expand Down
1 change: 1 addition & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
/* Android Designing and layout */
implementation(platform(libs.androidx.compose.bom))
implementation(libs.compose.material)
implementation(project(":core:domain"))
// implementation("androidx.test.ext:junit-ktx:1.2.1")

/* Testing */
Expand Down
175 changes: 155 additions & 20 deletions core/common/src/main/java/com/jetapps/jettaskboard/CreateformDropDown.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.toSize
import com.jetapps.jettaskboard.model.BoardModel
import com.jetapps.jettaskboard.model.ListModel

@Composable
fun CreateFormDropDown(
fun CreateBoardListFormDropDown(
headingText: String,
modifier: Modifier = Modifier,
contentMap: Map<String, String>,
initiallyOpened: Boolean = false
contentMap: Map<String, ListModel>,
initiallyOpened: Boolean = false,
onListSelected: (ListModel) -> Unit,
) {
var isOpen by remember { mutableStateOf(initiallyOpened) }

var dropDownWidth by remember { mutableStateOf(Size.Zero) }

var selectMenuItem by remember {
mutableStateOf("")
mutableStateOf<ListModel?>(null)
}

var selectedMenuItemHeading by remember {
Expand All @@ -61,8 +64,7 @@ fun CreateFormDropDown(

Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
.fillMaxWidth(),
horizontalAlignment = Alignment.Start
) {
Column(
Expand Down Expand Up @@ -127,6 +129,7 @@ fun CreateFormDropDown(
isOpen = !isOpen
selectMenuItem = itemValue
selectedMenuItemHeading = itemKey
onListSelected(itemValue)
},
modifier = Modifier
.background(color = MaterialTheme.colors.background)
Expand All @@ -147,7 +150,7 @@ fun CreateFormDropDown(
Text(
modifier = modifier
.padding(all = 4.dp),
text = itemValue,
text = itemValue.title ?: "",
fontWeight = FontWeight.Medium,
fontSize = 12.sp
)
Expand All @@ -159,16 +162,14 @@ fun CreateFormDropDown(
}
}

selectMenuItem.let { selectedItem ->
if (selectedItem.isNotEmpty()) {
Spacer(modifier = Modifier.height(8.dp))
selectMenuItem?.let { item ->
Spacer(modifier = Modifier.height(8.dp))

Text(
text = selectMenuItem.ifEmpty { " " },
fontSize = 12.sp,
modifier = Modifier.padding(8.dp)
)
}
Text(
text = item.title ?: " ",
fontSize = 12.sp,
modifier = Modifier.padding(8.dp)
)
}
}
}
Expand All @@ -177,15 +178,16 @@ fun CreateFormDropDown(
fun CreateBoardDropDown(
headingText: String,
modifier: Modifier = Modifier,
contentMap: Map<Color, String>,
initiallyOpened: Boolean = false
contentMap: Map<Color, BoardModel>,
initiallyOpened: Boolean = false,
onBoardSelected: (BoardModel) -> Unit,
) {
var isOpen by remember { mutableStateOf(initiallyOpened) }

var dropDownWidth by remember { mutableStateOf(Size.Zero) }

var selectMenuItem by remember {
mutableStateOf("")
mutableStateOf<BoardModel?>(null)
}

Column(
Expand Down Expand Up @@ -217,7 +219,7 @@ fun CreateBoardDropDown(
}
) {
Text(
text = selectMenuItem.ifEmpty { "Select from dropdown.. " },
text = selectMenuItem?.title ?: "Select from dropdown.. ",
color = Color.White,
fontSize = 18.sp,
modifier = Modifier
Expand Down Expand Up @@ -255,6 +257,7 @@ fun CreateBoardDropDown(
onClick = {
isOpen = !isOpen
selectMenuItem = itemValue
onBoardSelected(itemValue)
},
modifier = Modifier
.background(color = MaterialTheme.colors.background)
Expand All @@ -270,6 +273,126 @@ fun CreateBoardDropDown(
shape = RoundedCornerShape(4.dp),
backgroundColor = itemKey as Color
) {}
if (contentMap.values.isNotEmpty()) {
Text(
modifier = modifier
.padding(all = 4.dp),
text = itemValue.title,
fontWeight = FontWeight.Medium,
fontSize = 12.sp
)
}
}
}
}
}
}
}

@Composable
fun CreateVisibilityFormDropDown(
headingText: String,
modifier: Modifier = Modifier,
contentMap: Map<String, String>,
initiallyOpened: Boolean = false
) {
var isOpen by remember { mutableStateOf(initiallyOpened) }

var dropDownWidth by remember { mutableStateOf(Size.Zero) }

var selectMenuItem by remember {
mutableStateOf("")
}

var selectedMenuItemHeading by remember {
mutableStateOf(
""
)
}

Column(
modifier = Modifier
.fillMaxWidth(),
horizontalAlignment = Alignment.Start
) {
Column(
modifier = Modifier.clickable { isOpen = !isOpen }
) {
Text(
modifier = modifier
.padding(horizontal = 8.dp),
text = headingText,
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp
)

Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(8.dp)
.fillMaxWidth()
.background(Color.Transparent)
.onGloballyPositioned { coordinates ->
dropDownWidth = coordinates.size.toSize()
}
) {
Text(
text = selectedMenuItemHeading.ifEmpty { "Select from dropdown.. " },
color = Color.White,
fontSize = 18.sp,
modifier = Modifier
)
Icon(
imageVector = if (!isOpen) {
Icons.Default.KeyboardArrowDown
} else {
Icons.Default.KeyboardArrowUp
},
contentDescription = "Open or close the drop down",
tint = Color.White,
modifier = Modifier
)
}
}

Divider(
color = MaterialTheme.colors.onBackground
)

DropdownMenu(
expanded = isOpen,
onDismissRequest = { isOpen = false },
modifier = Modifier
.width(
with(LocalDensity.current) {
dropDownWidth.width.toDp()
}
)
.padding(horizontal = 8.dp)
) {
contentMap.forEach { (itemKey, itemValue) ->
DropdownMenuItem(
onClick = {
isOpen = !isOpen
selectMenuItem = itemValue
selectedMenuItemHeading = itemKey
},
modifier = Modifier
.background(color = MaterialTheme.colors.background)
) {
Column(
modifier = Modifier
.padding(8.dp),
horizontalAlignment = Alignment.Start
) {
Text(
modifier = modifier
.padding(all = 4.dp),
text = itemKey,
fontWeight = FontWeight.Bold,
fontSize = 14.sp
)
if (contentMap.values.isNotEmpty()) {
Text(
modifier = modifier
Expand All @@ -279,9 +402,21 @@ fun CreateBoardDropDown(
fontSize = 12.sp
)
}

Divider()
}
}
}
}

selectMenuItem.let { item ->
Spacer(modifier = Modifier.height(8.dp))

Text(
text = item,
fontSize = 12.sp,
modifier = Modifier.padding(8.dp)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jetapps.jettaskboard.di

import android.content.Context
import androidx.room.Room
import com.jetapps.jettaskboard.local.dao.BoardDao
import com.jetapps.jettaskboard.local.dao.DashboardDao
import com.jetapps.jettaskboard.local.dao.CardDao
import com.jetapps.jettaskboard.local.dao.LabelDao
Expand All @@ -21,7 +22,7 @@ object DatabaseModule {

@Provides
@Singleton
fun provideDatabase(@ApplicationContext context: Context) : JtbDatabase {
fun provideDatabase(@ApplicationContext context: Context): JtbDatabase {
return Room.databaseBuilder(
context,
JtbDatabase::class.java,
Expand All @@ -41,7 +42,11 @@ object DatabaseModule {

@Provides
@Singleton
fun providesBoardDao(database: JtbDatabase): DashboardDao = database.boardDao()
fun providesDashBoardDao(database: JtbDatabase): DashboardDao = database.dashboardDao()

@Provides
@Singleton
fun providesBoardDao(database: JtbDatabase): BoardDao = database.boardDao()

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import androidx.room.Transaction
import com.jetapps.jettaskboard.local.entity.CardEntity
import com.jetapps.jettaskboard.local.entity.ListEntity
import com.jetapps.jettaskboard.model.db.BoardWithLists
import kotlinx.coroutines.flow.Flow

@Dao
interface BoardDao {

@Transaction
@Query("SELECT * FROM boardTable WHERE boardId = :boardId")
fun getBoardWithListsAndCards(boardId: Int): BoardWithLists
fun getBoardWithListsAndCards(boardId: Long): Flow<BoardWithLists?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ interface CardDao {
@Query("SELECT * FROM cardTable")
fun getAllCards(): Flow<List<CardEntity>>

@Query("SELECT * FROM cardTable where cardId = :cardId")
fun fetchCardDetails(cardId: Long): CardEntity

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAllCards(cards: List<CardEntity>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import com.jetapps.jettaskboard.local.entity.BoardEntity
import com.jetapps.jettaskboard.local.entity.ListEntity
import com.jetapps.jettaskboard.model.db.BoardWithLists
import kotlinx.coroutines.flow.Flow

@Dao
Expand All @@ -18,10 +16,6 @@ interface DashboardDao {
@Query("SELECT * FROM boardTable")
fun getAllBoards(): Flow<List<BoardEntity>>

@Transaction
@Query("SELECT * FROM boardTable WHERE boardId = :boardId")
fun getBoardDetails(boardId: Int): Flow<BoardWithLists>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertBoard(board: BoardEntity)

Expand All @@ -38,5 +32,5 @@ interface DashboardDao {
fun getAllLists(): List<ListEntity>

@Query("SELECT * FROM listTable where boardId = :boardId")
fun getAllBoardRelatedLists(boardId: Int): List<ListEntity>
fun getAllBoardRelatedLists(boardId: Long): List<ListEntity>
}
Loading

0 comments on commit 4cfdbb4

Please sign in to comment.