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

시간표 블록 보여줄 정보 커스텀 #373

Merged
merged 7 commits into from
Oct 23, 2024
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
11 changes: 11 additions & 0 deletions app/src/main/java/com/wafflestudio/snutt2/data/SNUTTStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.wafflestudio.snutt2.lib.Optional
import com.wafflestudio.snutt2.lib.network.NetworkLog
import com.wafflestudio.snutt2.lib.network.dto.core.*
import com.wafflestudio.snutt2.lib.preferences.context.*
import com.wafflestudio.snutt2.model.TableLectureCustom
import com.wafflestudio.snutt2.model.TableTrimParam
import com.wafflestudio.snutt2.model.TagDto
import com.wafflestudio.snutt2.ui.ThemeMode
Expand Down Expand Up @@ -88,6 +89,16 @@ class SNUTTStorage @Inject constructor(
),
)

val tableLectureCustom = PrefValue<TableLectureCustom>(
prefContext,
PrefValueMetaData(
domain = DOMAIN_SCOPE_CURRENT_VERSION,
key = "table_lecture_custom",
type = TableLectureCustom::class.java,
defaultValue = TableLectureCustom.Default,
),
)

val themeMode = PrefValue<ThemeMode>(
prefContext,
PrefValueMetaData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.wafflestudio.snutt2.data.user

import com.wafflestudio.snutt2.lib.network.dto.GetUserFacebookResults
import com.wafflestudio.snutt2.lib.network.dto.core.UserDto
import com.wafflestudio.snutt2.model.TableLectureCustom
import com.wafflestudio.snutt2.model.TableLectureCustomOptions
import com.wafflestudio.snutt2.model.TableTrimParam
import com.wafflestudio.snutt2.ui.ThemeMode
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -11,6 +13,8 @@ interface UserRepository {

val tableTrimParam: StateFlow<TableTrimParam>

val tableLectureCustomOption: StateFlow<TableLectureCustom>

val accessToken: StateFlow<String>

val themeMode: StateFlow<ThemeMode>
Expand Down Expand Up @@ -96,6 +100,8 @@ interface UserRepository {

suspend fun setCompactMode(compact: Boolean)

suspend fun setTableLectureCustomOption(key: TableLectureCustomOptions, value: Boolean)

suspend fun setFirstBookmarkAlertShown()

suspend fun getAccessTokenByAuthCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.wafflestudio.snutt2.lib.network.SNUTTRestApiForGoogle
import com.wafflestudio.snutt2.lib.network.dto.*
import com.wafflestudio.snutt2.lib.toOptional
import com.wafflestudio.snutt2.lib.unwrap
import com.wafflestudio.snutt2.model.TableLectureCustom
import com.wafflestudio.snutt2.model.TableLectureCustomOptions
import com.wafflestudio.snutt2.model.TableTrimParam
import com.wafflestudio.snutt2.ui.ThemeMode
import com.wafflestudio.snutt2.views.logged_in.home.popups.PopupState
Expand All @@ -36,6 +38,9 @@ class UserRepositoryImpl @Inject constructor(

override val tableTrimParam: StateFlow<TableTrimParam> = storage.tableTrimParam.asStateFlow()

override val tableLectureCustomOption: StateFlow<TableLectureCustom> =
storage.tableLectureCustom.asStateFlow()

override val accessToken = storage.accessToken.asStateFlow()

override val themeMode = storage.themeMode.asStateFlow()
Expand Down Expand Up @@ -275,6 +280,17 @@ class UserRepositoryImpl @Inject constructor(
storage.compactMode.update(compact)
}

override suspend fun setTableLectureCustomOption(key: TableLectureCustomOptions, value: Boolean) {
storage.tableLectureCustom.update(
when (key) {
TableLectureCustomOptions.TITLE -> storage.tableLectureCustom.get().copy(title = value)
TableLectureCustomOptions.PLACE -> storage.tableLectureCustom.get().copy(place = value)
TableLectureCustomOptions.LECTURENUMBER -> storage.tableLectureCustom.get().copy(lectureNumber = value)
TableLectureCustomOptions.INSTRUCTOR -> storage.tableLectureCustom.get().copy(instructor = value)
},
)
}

override suspend fun setFirstBookmarkAlertShown() {
storage.firstBookmarkAlert.update(false)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.wafflestudio.snutt2.model

data class TableLectureCustom(
val title: Boolean,
val place: Boolean,
val lectureNumber: Boolean,
val instructor: Boolean,
) {
companion object {
val Default = TableLectureCustom(true, true, false, false)
}
}

enum class TableLectureCustomOptions {
TITLE,
PLACE,
LECTURENUMBER,
INSTRUCTOR,
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ fun HomePage() {
val table by timetableViewModel.currentTable.collectAsState()
val previewTheme by timetableViewModel.previewTheme.collectAsState()
val trimParam by userViewModel.trimParam.collectAsState()
val tableState = TableState(table ?: TableDto.Default, trimParam, previewTheme)
val tableLectureCustomOptions by userViewModel.tableLectureCustomOption.collectAsState()
val tableState = TableState(table ?: TableDto.Default, trimParam, tableLectureCustomOptions, previewTheme)
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
var shouldShowPopup by remember { mutableStateOf(false) }
var popupUri by remember { mutableStateOf("") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import com.wafflestudio.snutt2.R
import com.wafflestudio.snutt2.components.compose.SimpleTopBar
import com.wafflestudio.snutt2.lib.network.dto.core.TableDto
import com.wafflestudio.snutt2.model.TableLectureCustomOptions
import com.wafflestudio.snutt2.ui.SNUTTColors
import com.wafflestudio.snutt2.ui.SNUTTTypography
import com.wafflestudio.snutt2.views.LocalNavController
Expand All @@ -54,12 +55,14 @@ fun TimetableConfigPage() {
val viewModel = hiltViewModel<UserViewModel>()
val timetableViewModel = hiltViewModel<TimetableViewModel>()
val trimParam by viewModel.trimParam.collectAsState()
val tableLectureCustomOptions by viewModel.tableLectureCustomOption.collectAsState()
val compactMode by viewModel.compactMode.collectAsState()

val table by timetableViewModel.currentTable.collectAsState()
val previewTheme by timetableViewModel.previewTheme.collectAsState()

val tableState =
TableState(table ?: TableDto.Default, trimParam, previewTheme)
TableState(table ?: TableDto.Default, trimParam, tableLectureCustomOptions, previewTheme)

Column(
modifier = Modifier
Expand Down Expand Up @@ -128,7 +131,6 @@ fun TimetableConfigPage() {
}
Row(
modifier = Modifier
.height(40.dp)
.padding(horizontal = 20.dp, vertical = 3.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Expand All @@ -139,7 +141,68 @@ fun TimetableConfigPage() {
)
}
}
Margin(height = 10.dp)
SettingColumn(
title = stringResource(R.string.settings_timetable_lecture_custom),
) {
SettingItem(
title = stringResource(R.string.settings_timetable_lecture_custom_title),
hasNextPage = false,
onClick = {
scope.launch {
viewModel.setTableLectureCustomOption(TableLectureCustomOptions.TITLE, tableLectureCustomOptions.title.not())
}
},
) {
PoorSwitch(state = tableLectureCustomOptions.title)
}

SettingItem(
title = stringResource(R.string.settings_timetable_lecture_custom_place),
hasNextPage = false,
onClick = {
scope.launch {
viewModel.setTableLectureCustomOption(TableLectureCustomOptions.PLACE, tableLectureCustomOptions.place.not())
}
},
) {
PoorSwitch(state = tableLectureCustomOptions.place)
}

SettingItem(
title = stringResource(R.string.settings_timetable_lecture_custom_lecture_number),
hasNextPage = false,
onClick = {
scope.launch {
viewModel.setTableLectureCustomOption(TableLectureCustomOptions.LECTURENUMBER, tableLectureCustomOptions.lectureNumber.not())
}
},
) {
PoorSwitch(state = tableLectureCustomOptions.lectureNumber)
}

SettingItem(
title = stringResource(R.string.settings_timetable_lecture_custom_instructor),
hasNextPage = false,
onClick = {
scope.launch {
viewModel.setTableLectureCustomOption(TableLectureCustomOptions.INSTRUCTOR, tableLectureCustomOptions.instructor.not())
}
},
) {
PoorSwitch(state = tableLectureCustomOptions.instructor)
}
}
Text(
text = stringResource(R.string.settings_timetable_lecture_custom_warning),
style = SNUTTTypography.subtitle2.copy(fontSize = 12.sp),
modifier = Modifier.padding(horizontal = 16.dp, vertical = 5.dp),
)
Margin(height = 20.dp)
Text(
text = stringResource(R.string.settings_timetable_preview),
style = SNUTTTypography.subtitle2.copy(fontSize = 12.sp),
modifier = Modifier.padding(horizontal = 48.dp, vertical = 7.dp),
)
Box(
modifier = Modifier
.clip(RoundedCornerShape(5))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.wafflestudio.snutt2.views.logged_in.home.settings
import androidx.lifecycle.ViewModel
import com.wafflestudio.snutt2.data.user.UserRepository
import com.wafflestudio.snutt2.lib.network.dto.core.UserDto
import com.wafflestudio.snutt2.model.TableLectureCustom
import com.wafflestudio.snutt2.model.TableLectureCustomOptions
import com.wafflestudio.snutt2.model.TableTrimParam
import com.wafflestudio.snutt2.ui.ThemeMode
import com.wafflestudio.snutt2.views.logged_in.home.popups.PopupState
Expand All @@ -18,6 +20,8 @@ class UserViewModel @Inject constructor(

val trimParam: StateFlow<TableTrimParam> = userRepository.tableTrimParam

val tableLectureCustomOption: StateFlow<TableLectureCustom> = userRepository.tableLectureCustomOption

val userInfo: StateFlow<UserDto?> = userRepository.user

val accessToken: StateFlow<String> = userRepository.accessToken
Expand All @@ -44,6 +48,10 @@ class UserViewModel @Inject constructor(
userRepository.fetchUserInfo()
}

suspend fun setTableLectureCustomOption(key: TableLectureCustomOptions, value: Boolean) {
userRepository.setTableLectureCustomOption(key, value)
}

suspend fun loginLocal(id: String, password: String) {
userRepository.postSignIn(id, password)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ fun ThemeDetailPage(

val table by timetableViewModel.currentTable.collectAsState()
val trimParam by userViewModel.trimParam.collectAsState()
val tableLectureCustomOptions by userViewModel.tableLectureCustomOption.collectAsState()
val previewTheme by timetableViewModel.previewTheme.collectAsState()
val tableState =
TableState(table ?: TableDto.Default, trimParam, previewTheme)
TableState(table ?: TableDto.Default, trimParam, tableLectureCustomOptions, previewTheme)

val editingTheme by themeDetailViewModel.editingTheme.collectAsState()
val editingColors by themeDetailViewModel.editingColors.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.wafflestudio.snutt2.views.logged_in.home.timetable

import androidx.compose.runtime.Stable
import com.wafflestudio.snutt2.lib.network.dto.core.TableDto
import com.wafflestudio.snutt2.model.TableLectureCustom
import com.wafflestudio.snutt2.model.TableTheme
import com.wafflestudio.snutt2.model.TableTrimParam

@Stable
data class TableState(
val table: TableDto,
val trimParam: TableTrimParam,
val tableLectureCustomOptions: TableLectureCustom,
val previewTheme: TableTheme?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ private fun DrawClassTime(
val cellPadding = 4.dp
val compactMode = LocalCompactState.current
val textMeasurer = rememberTextMeasurer()
val tableLectureCustomOptions = LocalTableState.current.tableLectureCustomOptions

val dayOffset = classTime.day - fittedTrimParam.dayOfWeekFrom
val hourRangeOffset =
Expand Down Expand Up @@ -326,14 +327,15 @@ private fun DrawClassTime(
lectureNumber,
instructorName,
fittedTrimParam,
tableLectureCustomOptions,
) {
try {
calculateAdjustedTextLayout(
listOf(
LectureCellInfo.titleTextLayout(courseTitle, true),
LectureCellInfo.placeTextLayout(classTime.place, true),
LectureCellInfo.lectureNumberTextLayout(lectureNumber, false),
LectureCellInfo.instructorNameTextLayout(instructorName, false),
LectureCellInfo.titleTextLayout(courseTitle, tableLectureCustomOptions.title),
LectureCellInfo.placeTextLayout(classTime.place, tableLectureCustomOptions.place),
LectureCellInfo.lectureNumberTextLayout(lectureNumber, tableLectureCustomOptions.lectureNumber),
LectureCellInfo.instructorNameTextLayout(instructorName, tableLectureCustomOptions.instructor),
),
textMeasurer,
constraints,
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,13 @@
<string name="settings_timetable_config_force_fit">시간표 자동 정렬</string>
<string name="settings_timetable_config_week_day">요일</string>
<string name="settings_timetable_config_time">시간</string>
<string name="settings_timetable_lecture_custom">강의 정보</string>
<string name="settings_timetable_lecture_custom_title">강의명</string>
<string name="settings_timetable_lecture_custom_place">장소</string>
<string name="settings_timetable_lecture_custom_lecture_number">분반번호</string>
<string name="settings_timetable_lecture_custom_instructor">교수</string>
<string name="settings_timetable_lecture_custom_warning">정보가 많을 경우 일부 텍스트가 잘릴 수 있습니다.</string>
<string name="settings_timetable_preview">시간표 미리보기</string>
<string name="settings_user_config_change_nickname">닉네임 변경</string>
<string name="settings_user_config_copy_nickname">닉네임 복사하기</string>
<string name="settings_user_config_id">아이디</string>
Expand Down
Loading