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

release snutt 3.5.3 #266

Merged
merged 6 commits into from
Mar 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ThemeRepository {

val builtInThemes: StateFlow<List<BuiltInTheme>>

val currentTableTheme: StateFlow<TableTheme>
val currentTableTheme: StateFlow<TableTheme> // FIXME: 이게 ThemeRepository에 있는 게 맞나... ThemeRepository와 CurrentTableRepository에 의존하는 UseCase를 만들어야 할까?

suspend fun fetchThemes()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.wafflestudio.snutt2.data.themes

import com.wafflestudio.snutt2.data.SNUTTStorage
import com.wafflestudio.snutt2.lib.map
import com.wafflestudio.snutt2.lib.network.ApiOnError
import com.wafflestudio.snutt2.lib.network.SNUTTRestApi
import com.wafflestudio.snutt2.lib.network.dto.PatchThemeParams
import com.wafflestudio.snutt2.lib.network.dto.PostThemeParams
import com.wafflestudio.snutt2.lib.network.dto.core.ColorDto
import com.wafflestudio.snutt2.model.BuiltInTheme
import com.wafflestudio.snutt2.model.CustomTheme
import com.wafflestudio.snutt2.model.TableTheme
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -23,7 +21,6 @@ class ThemeRepositoryImpl @Inject constructor(
private val api: SNUTTRestApi,
private val storage: SNUTTStorage,
externalScope: CoroutineScope,
private val apiOnError: ApiOnError,
) : ThemeRepository {

private val _customThemes = MutableStateFlow<List<CustomTheme>>(emptyList())
Expand All @@ -32,25 +29,13 @@ class ThemeRepositoryImpl @Inject constructor(
private val _builtInThemes = MutableStateFlow<List<BuiltInTheme>>(emptyList())
override val builtInThemes: StateFlow<List<BuiltInTheme>> = _builtInThemes

private val _currentTableTheme = MutableStateFlow<TableTheme>(BuiltInTheme.SNUTT)
override val currentTableTheme = _currentTableTheme // FIXME: themeRepository에 넣기보다는 currentTableRepository와 themeRepository에 의존하는 UseCase를 만드는 게 낫지 않을까

init {
externalScope.launch {
runCatching {
fetchThemes()
}.onFailure(apiOnError)
storage.lastViewedTable.asStateFlow().map { table ->
table.value?.themeId?.let {
getTheme(it)
} ?: table.value?.theme?.let {
BuiltInTheme.fromCode(it)
} ?: BuiltInTheme.SNUTT
}.collect {
_currentTableTheme.value = it
}
}
}
override val currentTableTheme = combine(storage.lastViewedTable.asStateFlow(), _customThemes) { table, _ ->
table.value?.themeId?.let { themeId ->
getTheme(themeId)
} ?: table.value?.theme?.let {
BuiltInTheme.fromCode(it)
} ?: BuiltInTheme.SNUTT
}.stateIn(externalScope, SharingStarted.Eagerly, BuiltInTheme.SNUTT)

override suspend fun fetchThemes() {
api._getThemes().let { themes ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.wafflestudio.snutt2.views.logged_in.home.search.SearchPage
import com.wafflestudio.snutt2.views.logged_in.home.search.SearchViewModel
import com.wafflestudio.snutt2.views.logged_in.home.settings.SettingsPage
import com.wafflestudio.snutt2.views.logged_in.home.settings.UserViewModel
import com.wafflestudio.snutt2.views.logged_in.home.settings.theme.ThemeListViewModel
import com.wafflestudio.snutt2.views.logged_in.home.timetable.TableState
import com.wafflestudio.snutt2.views.logged_in.home.timetable.TimetablePage
import com.wafflestudio.snutt2.views.logged_in.home.timetable.TimetableViewModel
Expand All @@ -53,7 +52,6 @@ fun HomePage() {
val timetableViewModel = hiltViewModel<TimetableViewModel>()
val tableListViewModel = hiltViewModel<TableListViewModel>()
val searchViewModel = hiltViewModel<SearchViewModel>()
val themeListViewModel = hiltViewModel<ThemeListViewModel>()

val uncheckedNotification by homeViewModel.unCheckedNotificationExist.collectAsState()
val table by timetableViewModel.currentTable.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.wafflestudio.snutt2.RemoteConfig
import com.wafflestudio.snutt2.data.current_table.CurrentTableRepository
import com.wafflestudio.snutt2.data.notifications.NotificationRepository
import com.wafflestudio.snutt2.data.tables.TableRepository
import com.wafflestudio.snutt2.data.themes.ThemeRepository
import com.wafflestudio.snutt2.data.user.UserRepository
import com.wafflestudio.snutt2.lib.network.call_adapter.ErrorParsedHttpException
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -21,6 +22,7 @@ class HomeViewModel @Inject constructor(
private val tableRepository: TableRepository,
private val userRepository: UserRepository,
private val notificationRepository: NotificationRepository,
private val themeRepository: ThemeRepository,
private val remoteConfig: RemoteConfig,
) : ViewModel() {

Expand All @@ -41,6 +43,7 @@ class HomeViewModel @Inject constructor(
} ?: tableRepository.fetchDefaultTable()
},
async { userRepository.fetchUserInfo() },
async { themeRepository.fetchThemes() },
)
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -96,6 +97,12 @@ fun ThemeConfigPage(
onBackPressed()
}

LaunchedEffect(Unit) {
runCatching {
themeListViewModel.fetchThemes()
}.onFailure(apiOnError)
}

ModalBottomSheetLayout(
sheetState = bottomSheet.state,
sheetContent = bottomSheet.content,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
package com.wafflestudio.snutt2.views.logged_in.home.settings.theme

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wafflestudio.snutt2.data.current_table.CurrentTableRepository
import com.wafflestudio.snutt2.data.tables.TableRepository
import com.wafflestudio.snutt2.data.themes.ThemeRepository
import com.wafflestudio.snutt2.lib.network.ApiOnError
import com.wafflestudio.snutt2.model.BuiltInTheme
import com.wafflestudio.snutt2.model.CustomTheme
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ThemeListViewModel @Inject constructor(
private val themeRepository: ThemeRepository,
private val tableRepository: TableRepository,
currentTableRepository: CurrentTableRepository,
private val apiOnError: ApiOnError,
) : ViewModel() {

val customThemes: StateFlow<List<CustomTheme>> get() = themeRepository.customThemes
val builtInThemes: StateFlow<List<BuiltInTheme>> get() = themeRepository.builtInThemes

val currentTable = currentTableRepository.currentTable

init {
viewModelScope.launch {
runCatching {
themeRepository.fetchThemes()
}.onFailure(apiOnError)
}
suspend fun fetchThemes() {
themeRepository.fetchThemes()
}

suspend fun deleteThemeAndRefreshTableIfNeeded(themeId: String) { // 현재 선택된 시간표의 테마라면 서버에서 변경된 색 배치를 불러옴
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
snuttVersionName=3.5.2
snuttVersionName=3.5.3
Loading