Skip to content

Commit

Permalink
Merge pull request #91 from TimerTiTi/73-log-home-setting
Browse files Browse the repository at this point in the history
close #73 log home setting
  • Loading branch information
koreatlwls authored Mar 13, 2024
2 parents 8f6332c + 5fe30d3 commit 188f499
Show file tree
Hide file tree
Showing 24 changed files with 753 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -66,6 +67,7 @@ fun TdsDialog(
textStyle = TdsTextStyle.NORMAL_TEXT_STYLE,
fontSize = 13.sp,
color = TdsColor.TEXT,
textAlign = TextAlign.Center,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ fun TdsInputTimeTextField(
}
},
fontSize = 22.sp,
keyboardOptions =
KeyboardOptions(
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Decimal,
imeAction = ImeAction.Done,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -14,13 +13,15 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand All @@ -35,6 +36,7 @@ fun TdsTabRow(
items: List<String>,
modifier: Modifier = Modifier,
onClick: (index: Int) -> Unit,
indicatorColor: Color = TdsColor.SEGMENT_INDICATOR.getColor(),
) {
BoxWithConstraints(modifier = modifier) {
val tabWidth = maxWidth / items.size
Expand All @@ -55,6 +57,7 @@ fun TdsTabRow(
indicatorWidth = tabWidth,
indicatorHeight = tabHeight,
indicatorOffset = indicatorOffset,
indicatorColor = indicatorColor,
)

Row(
Expand Down Expand Up @@ -118,20 +121,20 @@ private fun TdsTabRowItem(
}

@Composable
private fun TdsTabRowIndicator(indicatorWidth: Dp, indicatorHeight: Dp, indicatorOffset: Dp) {
private fun TdsTabRowIndicator(
indicatorWidth: Dp,
indicatorHeight: Dp,
indicatorOffset: Dp,
indicatorColor: Color,
) {
Box(
modifier = Modifier
.offset(x = indicatorOffset)
.clip(RoundedCornerShape(4.dp))
.height(indicatorHeight)
.width(indicatorWidth)
.background(TdsColor.SEGMENT_INDICATOR.getColor())
.border(
width = 1.dp,
color = TdsColor.DIVIDER.getColor(),
shape = RoundedCornerShape(4.dp),
),

.padding(1.dp)
.clip(RoundedCornerShape(4.dp))
.background(indicatorColor),
)
}

Expand Down
14 changes: 14 additions & 0 deletions core/designsystem/src/main/res/drawable/setting_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="30dp"
android:viewportWidth="30"
android:viewportHeight="30">
<group>
<clip-path
android:pathData="M3,3h24.011v24h-24.011z"/>
<path
android:pathData="M13.872,26.989H16.139C17.003,26.989 17.665,26.461 17.867,25.631L18.349,23.533L18.708,23.41L20.537,24.531C21.267,24.992 22.108,24.879 22.725,24.262L24.296,22.703C24.913,22.086 25.025,21.233 24.565,20.515L23.421,18.697L23.555,18.361L25.654,17.867C26.473,17.665 27.011,16.992 27.011,16.139V13.917C27.011,13.064 26.484,12.391 25.654,12.189L23.578,11.684L23.432,11.325L24.576,9.508C25.037,8.79 24.924,7.948 24.307,7.32L22.736,5.749C22.13,5.143 21.289,5.031 20.56,5.48L18.731,6.602L18.349,6.456L17.867,4.358C17.665,3.527 17.003,3 16.139,3H13.872C13.008,3 12.346,3.527 12.144,4.358L11.651,6.456L11.269,6.602L9.452,5.48C8.722,5.031 7.87,5.143 7.264,5.749L5.704,7.32C5.087,7.948 4.964,8.79 5.435,9.508L6.568,11.325L6.433,11.684L4.358,12.189C3.527,12.391 3,13.064 3,13.917V16.139C3,16.992 3.539,17.665 4.358,17.867L6.456,18.361L6.579,18.697L5.446,20.515C4.975,21.233 5.098,22.086 5.715,22.703L7.275,24.262C7.892,24.879 8.745,24.992 9.474,24.531L11.292,23.41L11.651,23.533L12.144,25.631C12.346,26.461 13.008,26.989 13.872,26.989ZM14.052,25.238C13.861,25.238 13.76,25.16 13.726,24.98L13.053,22.198C12.369,22.029 11.729,21.76 11.247,21.457L8.801,22.961C8.666,23.062 8.52,23.039 8.386,22.905L7.062,21.581C6.938,21.457 6.927,21.323 7.017,21.166L8.52,18.742C8.262,18.271 7.971,17.631 7.791,16.947L5.008,16.285C4.829,16.251 4.75,16.15 4.75,15.959V14.086C4.75,13.884 4.818,13.794 5.008,13.76L7.78,13.087C7.959,12.358 8.296,11.696 8.498,11.281L7.006,8.857C6.905,8.689 6.916,8.554 7.039,8.419L8.374,7.118C8.509,6.983 8.633,6.961 8.801,7.062L11.224,8.532C11.707,8.262 12.391,7.982 13.064,7.791L13.726,5.008C13.76,4.829 13.861,4.75 14.052,4.75H15.959C16.15,4.75 16.251,4.829 16.274,5.008L16.958,7.813C17.654,7.993 18.26,8.274 18.764,8.543L21.199,7.062C21.379,6.961 21.491,6.983 21.637,7.118L22.961,8.419C23.095,8.554 23.095,8.689 22.994,8.857L21.502,11.281C21.715,11.696 22.041,12.358 22.22,13.087L25.003,13.76C25.182,13.794 25.261,13.884 25.261,14.086V15.959C25.261,16.15 25.171,16.251 25.003,16.285L22.209,16.947C22.029,17.631 21.749,18.271 21.48,18.742L22.983,21.166C23.073,21.323 23.073,21.457 22.938,21.581L21.625,22.905C21.48,23.039 21.345,23.062 21.199,22.961L18.753,21.457C18.271,21.76 17.642,22.029 16.958,22.198L16.274,24.98C16.251,25.16 16.15,25.238 15.959,25.238H14.052ZM15.006,19.281C17.351,19.281 19.281,17.351 19.281,14.994C19.281,12.661 17.351,10.731 15.006,10.731C12.661,10.731 10.719,12.661 10.719,14.994C10.719,17.339 12.649,19.281 15.006,19.281ZM15.006,17.541C13.614,17.541 12.47,16.397 12.47,14.994C12.47,13.614 13.614,12.47 15.006,12.47C16.375,12.47 17.519,13.614 17.519,14.994C17.519,16.386 16.375,17.541 15.006,17.541Z"
android:fillColor="#ffffff"
android:fillAlpha="0.85"/>
</group>
</vector>
10 changes: 10 additions & 0 deletions core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@
<string name="stopwatch_alarm_message">시간 경과되었습니다.</string>
<string name="alarm_permission_title">알람을 설정하기 위해 권한이 필요로 합니다.</string>
<string name="alarm_permission_message">설정하러 가시겠습니까?</string>

<string name="log_setting_color_title">컬러</string>
<string name="log_setting_color_message">그래프의 컬러를 설정 합니다</string>
<string name="log_setting_color_direction_title">컬러 방향</string>
<string name="log_setting_color_direction_message">컬러 조합의 방향을 설정 합니다</string>
<string name="log_setting_goal_time_title">목표 시간</string>
<string name="log_setting_goal_time_message">원형 프로그래스바의 목표 시간을 설정 합니다</string>

<string name="month_goal_time_dialog_message">Month의 목표 시간을 입력해 주세요\n(시간 단위)</string>
<string name="week_goal_time_dialog_message">Week의 목표 시간을 입력해 주세요\n(시간 단위)</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.titi.app.data.graph.api

import com.titi.app.data.graph.api.model.GraphCheckedRepositoryModel
import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel
import kotlinx.coroutines.flow.Flow

interface GraphCheckedRepository {
interface GraphRepository {

suspend fun setGraphChecked(graphCheckedRepositoryModel: GraphCheckedRepositoryModel)

fun getGraphCheckedFlow(): Flow<GraphCheckedRepositoryModel>

suspend fun setGraphGoalTime(graphGoalTimeRepositoryModel: GraphGoalTimeRepositoryModel)

fun getGraphGoalTimeFlow(): Flow<GraphGoalTimeRepositoryModel>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.titi.app.data.graph.api.model

data class GraphGoalTimeRepositoryModel(
val monthGoalTime: Int,
val weekGoalTime: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.titi.app.data.graph.impl.di

import android.content.Context
import com.titi.app.data.graph.impl.local.GraphCheckedDataStore
import com.titi.app.data.graph.impl.local.GraphGoalTimeDataStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -16,4 +17,9 @@ internal object DataStoreModule {
@Provides
fun provideGraphCheckedDataStore(@ApplicationContext context: Context) =
GraphCheckedDataStore(context)

@Singleton
@Provides
fun provideGraphGoalTimeDataStore(@ApplicationContext context: Context) =
GraphGoalTimeDataStore(context)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.titi.app.data.graph.impl.di

import com.titi.app.data.graph.api.GraphCheckedRepository
import com.titi.app.data.graph.impl.repository.GraphCheckedRepositoryImpl
import com.titi.app.data.graph.api.GraphRepository
import com.titi.app.data.graph.impl.repository.GraphRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -13,7 +13,5 @@ import javax.inject.Singleton
internal interface RepositoryModule {
@Binds
@Singleton
fun provideGraphCheckedRepository(
graphCheckedRepositoryImpl: GraphCheckedRepositoryImpl,
): GraphCheckedRepository
fun provideGraphRepository(graphRepositoryImpl: GraphRepositoryImpl): GraphRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.titi.app.data.graph.impl.local

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.titi.app.core.util.fromJson
import com.titi.app.core.util.readFlowValue
import com.titi.app.core.util.storeValue
import com.titi.app.core.util.toJson
import com.titi.app.data.graph.impl.local.model.GraphGoalTimeEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

internal class GraphGoalTimeDataStore(context: Context) {
private val dataStore: DataStore<Preferences> = context.dataStore

suspend fun setGraphGoalTime(graphGoalTimeEntity: GraphGoalTimeEntity) {
dataStore.storeValue(GRAPH_GOAL_TIME_KEY, graphGoalTimeEntity.toJson())
}

fun getGraphGoalTimeFlow(): Flow<GraphGoalTimeEntity?> {
return dataStore.readFlowValue(GRAPH_GOAL_TIME_KEY).map { it?.fromJson() }
}

companion object {
private const val GRAPH_GOAL_TIME_PREF_NAME = "graphGoalTimePrefName"
private val GRAPH_GOAL_TIME_KEY = stringPreferencesKey("graphGoalTimeKey")

private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
name = GRAPH_GOAL_TIME_PREF_NAME,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.titi.app.data.graph.impl.local.model

internal data class GraphGoalTimeEntity(
val monthGoalTime: Int,
val weekGoalTime: Int,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.titi.app.data.graph.impl.mapper

import com.titi.app.data.graph.api.model.GraphCheckedRepositoryModel
import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel
import com.titi.app.data.graph.impl.local.model.GraphCheckedEntity
import com.titi.app.data.graph.impl.local.model.GraphGoalTimeEntity

internal fun GraphCheckedEntity.toRepositoryModel() = GraphCheckedRepositoryModel(
checkedButtonStates = checkedButtonStates,
)

internal fun GraphGoalTimeEntity.toRepositoryModel() = GraphGoalTimeRepositoryModel(
monthGoalTime = monthGoalTime,
weekGoalTime = weekGoalTime,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.titi.app.data.graph.impl.mapper

import com.titi.app.data.graph.api.model.GraphCheckedRepositoryModel
import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel
import com.titi.app.data.graph.impl.local.model.GraphCheckedEntity
import com.titi.app.data.graph.impl.local.model.GraphGoalTimeEntity

internal fun GraphCheckedRepositoryModel.toLocalModel() = GraphCheckedEntity(
checkedButtonStates = checkedButtonStates,
)

internal fun GraphGoalTimeRepositoryModel.toLocalModel() = GraphGoalTimeEntity(
monthGoalTime = monthGoalTime,
weekGoalTime = weekGoalTime,
)
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.titi.app.data.graph.impl.repository

import com.titi.app.data.graph.api.GraphCheckedRepository
import com.titi.app.data.graph.api.GraphRepository
import com.titi.app.data.graph.api.model.GraphCheckedRepositoryModel
import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel
import com.titi.app.data.graph.impl.local.GraphCheckedDataStore
import com.titi.app.data.graph.impl.local.GraphGoalTimeDataStore
import com.titi.app.data.graph.impl.mapper.toLocalModel
import com.titi.app.data.graph.impl.mapper.toRepositoryModel
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map

internal class GraphCheckedRepositoryImpl @Inject constructor(
internal class GraphRepositoryImpl @Inject constructor(
private val graphCheckedDataStore: GraphCheckedDataStore,
) : GraphCheckedRepository {
private val graphGoalTimeDataStore: GraphGoalTimeDataStore,
) : GraphRepository {
override suspend fun setGraphChecked(graphCheckedRepositoryModel: GraphCheckedRepositoryModel) {
graphCheckedDataStore.setGraphChecked(graphCheckedRepositoryModel.toLocalModel())
}
Expand All @@ -23,4 +26,17 @@ internal class GraphCheckedRepositoryImpl @Inject constructor(
.filterNotNull()
.map { it.toRepositoryModel() }
}

override suspend fun setGraphGoalTime(
graphGoalTimeRepositoryModel: GraphGoalTimeRepositoryModel,
) {
graphGoalTimeDataStore.setGraphGoalTime(graphGoalTimeRepositoryModel.toLocalModel())
}

override fun getGraphGoalTimeFlow(): Flow<GraphGoalTimeRepositoryModel> {
return graphGoalTimeDataStore
.getGraphGoalTimeFlow()
.filterNotNull()
.map { it.toRepositoryModel() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,13 @@ internal fun Pair<Map<String, Long>, List<Daily>>.toHomeFeatureModel(
topTotalTdsTaskData = totalTopLevelTdsTaskData,
),
homeGraphData = HomeUiState.HomeGraphData(
homeMonthPieData = HomeUiState.HomeMonthPieData(
totalTimeSeconds = monthTotalTime,
),
homeMonthGraphData = HomeUiState.HomeMonthGraphData(
totalTimeSeconds = monthTotalTime,
taskData = monthTopTdsTaskData,
),
homeWeekPieData = HomeUiState.HomeWeekPieData(
totalTimeSeconds = weekTotalTime,
),
homeWeekGraphData = HomeUiState.HomeWeekGraphData(
weekInformation = currentDate.getWeekInformation(),
totalTimeSeconds = weekTotalTime,
totalWeekTime = weekTotalTime.getTimeString(),
averageWeekTime = (weekTotalTime / weekStudyCount).getTimeString(),
weekLineChartData = weekLineChartData,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.titi.app.feature.log.mapper

import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel
import com.titi.app.feature.log.model.GraphGoalTimeUiState

internal fun GraphGoalTimeUiState.toRepositoryModel() = GraphGoalTimeRepositoryModel(
monthGoalTime = monthGoalTime,
weekGoalTime = weekGoalTime,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.titi.app.feature.log.mapper

import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel
import com.titi.app.feature.log.model.GraphGoalTimeUiState

internal fun GraphGoalTimeRepositoryModel.toFeatureModel() = GraphGoalTimeUiState(
monthGoalTime = monthGoalTime,
weekGoalTime = weekGoalTime,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import com.titi.app.domain.color.model.GraphColor
import java.time.LocalDate

data class LogUiState(
val graphColors: GraphColorUiState = GraphColorUiState(),
val graphGoalTimeUiState: GraphGoalTimeUiState = GraphGoalTimeUiState(),
val graphColorUiState: GraphColorUiState = GraphColorUiState(),
val homeUiState: HomeUiState = HomeUiState(),
val dailyUiState: DailyUiState = DailyUiState(),
val weekUiState: WeekUiState = WeekUiState(),
) : MavericksState

data class GraphGoalTimeUiState(
val monthGoalTime: Int = 100,
val weekGoalTime: Int = 30,
)

data class GraphColorUiState(
val selectedIndex: Int = 0,
val direction: GraphColor.GraphDirection = GraphColor.GraphDirection.Right,
Expand Down Expand Up @@ -47,30 +53,19 @@ data class HomeUiState(
)

data class HomeGraphData(
val homeMonthPieData: HomeMonthPieData = HomeMonthPieData(),
val homeMonthGraphData: HomeMonthGraphData = HomeMonthGraphData(),
val homeWeekPieData: HomeWeekPieData = HomeWeekPieData(),
val homeWeekGraphData: HomeWeekGraphData = HomeWeekGraphData(),
val homeDailyGraphData: HomeDailyGraphData = HomeDailyGraphData(),
)

data class HomeMonthPieData(
val totalTimeSeconds: Long = 0,
val defaultTimeSeconds: Long = 360000,
)

data class HomeMonthGraphData(
val totalTimeSeconds: Long = 0,
val taskData: List<TdsTaskData> = emptyList(),
)

data class HomeWeekPieData(
val totalTimeSeconds: Long = 0,
val defaultTimeSeconds: Long = 90000,
)

data class HomeWeekGraphData(
val weekInformation: Triple<String, String, String> = LocalDate.now().getWeekInformation(),
val totalTimeSeconds: Long = 0L,
val totalWeekTime: String = 0L.getTimeString(),
val averageWeekTime: String = 0L.getTimeString(),
val weekLineChartData: List<TdsWeekLineChartData> =
Expand Down
Loading

0 comments on commit 188f499

Please sign in to comment.