From a4697037aa6cba04b93785420678827571ea640a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=91=EC=A3=BC=ED=98=84?= Date: Thu, 24 Oct 2024 03:08:48 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=9C=EA=B0=84=ED=91=9C=20=EB=B8=94?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=B4=EC=97=AC=EC=A4=84=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=BB=A4=EC=8A=A4=ED=85=80=20(#373)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: plgafhd --- .../wafflestudio/snutt2/data/SNUTTStorage.kt | 11 +++ .../snutt2/data/user/UserRepository.kt | 6 ++ .../snutt2/data/user/UserRepositoryImpl.kt | 16 +++++ .../snutt2/model/TableLectureCustom.kt | 19 +++++ .../snutt2/views/logged_in/home/HomePage.kt | 3 +- .../home/settings/TimetableConfigPage.kt | 69 ++++++++++++++++++- .../logged_in/home/settings/UserViewModel.kt | 8 +++ .../home/settings/theme/ThemeDetailPage.kt | 3 +- .../logged_in/home/timetable/TableState.kt | 2 + .../logged_in/home/timetable/TimeTable.kt | 10 +-- app/src/main/res/values/strings.xml | 7 ++ 11 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/snutt2/model/TableLectureCustom.kt diff --git a/app/src/main/java/com/wafflestudio/snutt2/data/SNUTTStorage.kt b/app/src/main/java/com/wafflestudio/snutt2/data/SNUTTStorage.kt index 677d6046e..37edcd21f 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/data/SNUTTStorage.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/data/SNUTTStorage.kt @@ -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 @@ -88,6 +89,16 @@ class SNUTTStorage @Inject constructor( ), ) + val tableLectureCustom = PrefValue( + prefContext, + PrefValueMetaData( + domain = DOMAIN_SCOPE_CURRENT_VERSION, + key = "table_lecture_custom", + type = TableLectureCustom::class.java, + defaultValue = TableLectureCustom.Default, + ), + ) + val themeMode = PrefValue( prefContext, PrefValueMetaData( diff --git a/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepository.kt b/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepository.kt index 581e3f97a..562b46b61 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepository.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepository.kt @@ -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 @@ -11,6 +13,8 @@ interface UserRepository { val tableTrimParam: StateFlow + val tableLectureCustomOption: StateFlow + val accessToken: StateFlow val themeMode: StateFlow @@ -96,6 +100,8 @@ interface UserRepository { suspend fun setCompactMode(compact: Boolean) + suspend fun setTableLectureCustomOption(key: TableLectureCustomOptions, value: Boolean) + suspend fun setFirstBookmarkAlertShown() suspend fun getAccessTokenByAuthCode( diff --git a/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepositoryImpl.kt b/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepositoryImpl.kt index 8620eddba..60aa671b6 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepositoryImpl.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/data/user/UserRepositoryImpl.kt @@ -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 @@ -36,6 +38,9 @@ class UserRepositoryImpl @Inject constructor( override val tableTrimParam: StateFlow = storage.tableTrimParam.asStateFlow() + override val tableLectureCustomOption: StateFlow = + storage.tableLectureCustom.asStateFlow() + override val accessToken = storage.accessToken.asStateFlow() override val themeMode = storage.themeMode.asStateFlow() @@ -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) } diff --git a/app/src/main/java/com/wafflestudio/snutt2/model/TableLectureCustom.kt b/app/src/main/java/com/wafflestudio/snutt2/model/TableLectureCustom.kt new file mode 100644 index 000000000..95e59156a --- /dev/null +++ b/app/src/main/java/com/wafflestudio/snutt2/model/TableLectureCustom.kt @@ -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, +} diff --git a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/HomePage.kt b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/HomePage.kt index 9597fd373..e62286997 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/HomePage.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/HomePage.kt @@ -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("") } diff --git a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/TimetableConfigPage.kt b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/TimetableConfigPage.kt index 05d4888c8..8d8c59323 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/TimetableConfigPage.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/TimetableConfigPage.kt @@ -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 @@ -54,12 +55,14 @@ fun TimetableConfigPage() { val viewModel = hiltViewModel() val timetableViewModel = hiltViewModel() 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 @@ -128,7 +131,6 @@ fun TimetableConfigPage() { } Row( modifier = Modifier - .height(40.dp) .padding(horizontal = 20.dp, vertical = 3.dp), verticalAlignment = Alignment.CenterVertically, ) { @@ -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)) diff --git a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/UserViewModel.kt b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/UserViewModel.kt index 4a2c81796..9f6a5c840 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/UserViewModel.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/UserViewModel.kt @@ -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 @@ -18,6 +20,8 @@ class UserViewModel @Inject constructor( val trimParam: StateFlow = userRepository.tableTrimParam + val tableLectureCustomOption: StateFlow = userRepository.tableLectureCustomOption + val userInfo: StateFlow = userRepository.user val accessToken: StateFlow = userRepository.accessToken @@ -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) } diff --git a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/theme/ThemeDetailPage.kt b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/theme/ThemeDetailPage.kt index 4a77427df..155bf4317 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/theme/ThemeDetailPage.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/settings/theme/ThemeDetailPage.kt @@ -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() diff --git a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TableState.kt b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TableState.kt index 8f84efa3f..cf9ac5364 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TableState.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TableState.kt @@ -2,6 +2,7 @@ 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 @@ -9,5 +10,6 @@ import com.wafflestudio.snutt2.model.TableTrimParam data class TableState( val table: TableDto, val trimParam: TableTrimParam, + val tableLectureCustomOptions: TableLectureCustom, val previewTheme: TableTheme?, ) diff --git a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TimeTable.kt b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TimeTable.kt index 3ccec9a93..6623dc2e0 100644 --- a/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TimeTable.kt +++ b/app/src/main/java/com/wafflestudio/snutt2/views/logged_in/home/timetable/TimeTable.kt @@ -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 = @@ -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, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd97443d4..c8712349d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -418,6 +418,13 @@ 시간표 자동 정렬 요일 시간 + 강의 정보 + 강의명 + 장소 + 분반번호 + 교수 + 정보가 많을 경우 일부 텍스트가 잘릴 수 있습니다. + 시간표 미리보기 닉네임 변경 닉네임 복사하기 아이디