Skip to content

Commit

Permalink
Merge branch 'dev' into feature/loginUI
Browse files Browse the repository at this point in the history
  • Loading branch information
flashdragon authored Nov 7, 2024
2 parents 63922f3 + 9bd8785 commit fc0ec1f
Show file tree
Hide file tree
Showing 23 changed files with 231 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fun DreamDiaryNavHost(
modifier = modifier,
) {
diaryHomeScreen(
onDiaryClick = { /*TODO: 상세 화면으로 이동*/ },
onDiaryClick = {
},
onFabClick = {
navController.navigateToDiaryWriteScreen(
navOptions = navOptions {
Expand All @@ -32,6 +33,8 @@ fun DreamDiaryNavHost(
},
)

diaryWriteScreen()
diaryWriteScreen(
onBackClick = navController::navigateUp,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "99fe4ad42dc76bf2ace29255e371e197",
"identityHash": "55c710c5b13d4a5c2c7517208401c5e1",
"entities": [
{
"tableName": "diary",
Expand Down Expand Up @@ -47,12 +47,32 @@
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "label",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`label` TEXT NOT NULL, PRIMARY KEY(`label`))",
"fields": [
{
"fieldPath": "label",
"columnName": "label",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"label"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '99fe4ad42dc76bf2ace29255e371e197')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '55c710c5b13d4a5c2c7517208401c5e1')"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.boostcamp.dreamteam.dreamdiary.core.data.database.dao.DreamDiaryDao
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.DreamDiaryEntity
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.LabelEntity

@Database(entities = [DreamDiaryEntity::class], version = 1)
@Database(entities = [DreamDiaryEntity::class, LabelEntity::class], version = 1)
@TypeConverters(value = [InstantTypeConverter::class])
internal abstract class DreamDiaryDatabase : RoomDatabase() {
abstract fun dreamDiaryDao(): DreamDiaryDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package com.boostcamp.dreamteam.dreamdiary.core.data.database.dao
import androidx.room.Dao
import androidx.room.Insert
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.DreamDiaryEntity
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.LabelEntity

@Dao
interface DreamDiaryDao {
@Insert
suspend fun insertDreamDiary(dreamDiaryEntity: DreamDiaryEntity)

@Insert
suspend fun insertLabel(labelEntity: LabelEntity)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.boostcamp.dreamteam.dreamdiary.core.data.database.model

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(
tableName = "label",
)
data class LabelEntity(
@PrimaryKey
val label: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.boostcamp.dreamteam.dreamdiary.core.data.repository

import com.boostcamp.dreamteam.dreamdiary.core.data.database.dao.DreamDiaryDao
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.DreamDiaryEntity
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.LabelEntity
import java.time.Instant
import java.util.UUID
import javax.inject.Inject
Expand All @@ -23,4 +24,12 @@ internal class DefaultDreamDiaryRepository @Inject constructor(
),
)
}

override suspend fun addLabel(label: String) {
dreamDiaryDao.insertLabel(
LabelEntity(
label = label,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ interface DreamDiaryRepository {
title: String,
body: String,
)

suspend fun addLabel(label: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.boostcamp.dreamteam.dreamdiary.core.domain.usecase

import com.boostcamp.dreamteam.dreamdiary.core.data.repository.DreamDiaryRepository
import javax.inject.Inject

class AddLabelUseCase @Inject constructor(
private val diaryRepository: DreamDiaryRepository,
) {
suspend operator fun invoke(label: String) {
return diaryRepository.addLabel(label)
}
}
2 changes: 1 addition & 1 deletion feature/diary/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ android {

dependencies {
implementation(projects.core.designsystem)
implementation(projects.core.model)
implementation(projects.core.domain)
implementation(projects.core.model)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.boostcamp.dreamteam.dreamdiary.core.model.Diary
import com.boostcamp.dreamteam.dreamdiary.feature.diary.models.DiaryUi
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -13,7 +13,7 @@ data object DiaryHomeRoute
fun NavController.navigateToDiaryHomeScreen(navOptions: NavOptions) = navigate(route = DiaryHomeRoute, navOptions)

fun NavGraphBuilder.diaryHomeScreen(
onDiaryClick: (Diary) -> Unit,
onDiaryClick: (DiaryUi) -> Unit,
onFabClick: () -> Unit,
) {
composable<DiaryHomeRoute> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PrimaryTabRow
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Tab
Expand All @@ -28,17 +27,17 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.boostcamp.dreamteam.dreamdiary.core.model.Diary
import com.boostcamp.dreamteam.dreamdiary.feature.diary.DiaryViewModel
import com.boostcamp.dreamteam.dreamdiary.designsystem.theme.DreamdiaryTheme
import com.boostcamp.dreamteam.dreamdiary.feature.diary.home.components.DiaryCalendarTab
import com.boostcamp.dreamteam.dreamdiary.feature.diary.home.components.DiaryListTab
import com.boostcamp.dreamteam.dreamdiary.feature.diary.home.components.diariesPreview
import com.boostcamp.dreamteam.dreamdiary.feature.diary.models.DiaryUi

@Composable
fun DiaryHomeScreen(
onDiaryClick: (Diary) -> Unit,
onDiaryClick: (DiaryUi) -> Unit,
onFabClick: () -> Unit,
viewModel: DiaryViewModel = hiltViewModel(),
viewModel: DiaryHomeViewModel = hiltViewModel(),
) {
val state by viewModel.diaryHomeUIState.collectAsStateWithLifecycle()
val diaries = state.diaries
Expand All @@ -55,12 +54,12 @@ fun DiaryHomeScreen(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun DiaryHomeScreenContent(
diaries: List<Diary>,
diaries: List<DiaryUi>,
modifier: Modifier = Modifier,
onMenuClick: () -> Unit = {},
onSearchClick: () -> Unit = {},
onNotificationClick: () -> Unit = {},
onDiaryClick: (Diary) -> Unit = {},
onDiaryClick: (DiaryUi) -> Unit = {},
onFabClick: () -> Unit = {},
) {
var selectedTabIndex by remember { mutableIntStateOf(0) }
Expand Down Expand Up @@ -168,8 +167,7 @@ private fun DiaryHomeScreenTopAppBar(
@Preview
@Composable
private fun DiaryHomeScreenContentPreview() {
// TODO: 테마 적용
MaterialTheme {
DreamdiaryTheme {
DiaryHomeScreenContent(
diaries = diariesPreview,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.boostcamp.dreamteam.dreamdiary.feature.diary.home

import com.boostcamp.dreamteam.dreamdiary.feature.diary.models.DiaryUi

data class DiaryHomeUIState(
val diaries: List<DiaryUi> = listOf(),
val loading: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.boostcamp.dreamteam.dreamdiary.feature.diary
package com.boostcamp.dreamteam.dreamdiary.feature.diary.home

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.boostcamp.dreamteam.dreamdiary.core.domain.usecase.GetDiariesUseCase
import com.boostcamp.dreamteam.dreamdiary.feature.diary.models.toDiaryUi
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class DiaryViewModel @Inject constructor(
class DiaryHomeViewModel @Inject constructor(
getDiariesUseCase: GetDiariesUseCase,
) : ViewModel() {
private val _diaryHomeUIState: MutableStateFlow<DiaryHomeUIState> =
Expand All @@ -19,7 +20,10 @@ class DiaryViewModel @Inject constructor(

init {
viewModelScope.launch {
_diaryHomeUIState.value = DiaryHomeUIState(getDiariesUseCase(), false)
_diaryHomeUIState.value = DiaryHomeUIState(
diaries = getDiariesUseCase().map { it.toDiaryUi() },
loading = false,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import com.boostcamp.dreamteam.dreamdiary.core.model.Diary
import com.boostcamp.dreamteam.dreamdiary.core.model.Label
import com.boostcamp.dreamteam.dreamdiary.designsystem.theme.DreamdiaryTheme
import com.boostcamp.dreamteam.dreamdiary.feature.diary.models.DiaryUi
import com.boostcamp.dreamteam.dreamdiary.feature.diary.models.toDiaryUi

@Composable
internal fun DiaryCard(
diary: Diary,
diary: DiaryUi,
modifier: Modifier = Modifier,
onDiaryClick: (Diary) -> Unit = {},
onDiaryClick: (DiaryUi) -> Unit = {},
containerColor: Color = MaterialTheme.colorScheme.surfaceContainerLowest,
) {
Card(
Expand Down Expand Up @@ -71,7 +74,7 @@ internal fun DiaryCard(
.padding(2.dp),
)
Spacer(modifier = Modifier.width(4.dp))
Text(text = diary.createdAt, style = MaterialTheme.typography.labelMedium)
Text(text = diary.createdAt.formatted, style = MaterialTheme.typography.labelMedium)

Spacer(modifier = Modifier.width(8.dp))

Expand Down Expand Up @@ -101,11 +104,12 @@ internal fun DiaryCard(
@Preview
@Composable
private fun DiaryCardPreview() {
// TODO: 테마 적용
DiaryCard(
diary = diaryPreview1,
modifier = Modifier.fillMaxWidth(),
)
DreamdiaryTheme {
DiaryCard(
diary = diaryPreview1,
modifier = Modifier.fillMaxWidth(),
)
}
}

internal val diaryPreview1 = Diary(
Expand All @@ -120,7 +124,7 @@ internal val diaryPreview1 = Diary(
Label("행복"),
Label("환희"),
),
)
).toDiaryUi()

internal val diaryPreview2 = Diary(
id = 2,
Expand All @@ -133,4 +137,4 @@ internal val diaryPreview2 = Diary(
Label("슬픔"),
Label("우울"),
),
)
).toDiaryUi()
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.boostcamp.dreamteam.dreamdiary.core.model.Diary
import com.boostcamp.dreamteam.dreamdiary.designsystem.theme.DreamdiaryTheme
import com.boostcamp.dreamteam.dreamdiary.feature.diary.models.DiaryUi

@Composable
internal fun DiaryListTab(
diaries: List<Diary>,
diaries: List<DiaryUi>,
modifier: Modifier = Modifier,
onDiaryClick: (Diary) -> Unit = {},
onDiaryClick: (DiaryUi) -> Unit = {},
) {
LazyColumn(
modifier = modifier,
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
items(diaries) { diary: Diary ->
items(diaries) { diary ->
DiaryCard(
diary = diary,
modifier = Modifier.fillMaxWidth(),
Expand All @@ -35,10 +36,12 @@ internal fun DiaryListTab(
@Preview
@Composable
private fun DiaryListTabPreview() {
DiaryListTab(diaries = diariesPreview)
DreamdiaryTheme {
DiaryListTab(diaries = diariesPreview)
}
}

internal val diariesPreview: List<Diary> = listOf(
internal val diariesPreview = listOf(
diaryPreview1,
diaryPreview2,
)
Loading

0 comments on commit fc0ec1f

Please sign in to comment.