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

위젯 다크 모드 추가 #384

Merged
merged 1 commit into from
Jan 12, 2025
Merged
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 @@ -8,6 +8,7 @@ import android.view.MotionEvent
import android.view.View
import androidx.core.content.res.ResourcesCompat
import com.wafflestudio.snutt2.R
import com.wafflestudio.snutt2.data.SNUTTStorage
import com.wafflestudio.snutt2.lib.contains
import com.wafflestudio.snutt2.lib.getFittingTrimParam
import com.wafflestudio.snutt2.lib.network.dto.core.ClassTimeDto
Expand All @@ -18,12 +19,12 @@ import com.wafflestudio.snutt2.lib.rx.sp
import com.wafflestudio.snutt2.lib.toDayString
import com.wafflestudio.snutt2.model.BuiltInTheme
import com.wafflestudio.snutt2.model.TableTrimParam
import com.wafflestudio.snutt2.ui.isSystemDarkMode
import io.reactivex.rxjava3.core.Observable
import kotlin.math.max
import kotlin.math.min

class TimetableView : View {

private val hourLabelWidth = 24.5f.dp(context)
private val dayLabelHeight = 28.5f.dp(context)
private val cellPadding = 4.dp(context)
Expand Down Expand Up @@ -132,7 +133,29 @@ class TimetableView : View {
}

private fun init() {
setBackgroundColor(Color.rgb(255, 255, 255))
val sharedPreferences = context.getSharedPreferences(SNUTTStorage.DOMAIN_SCOPE_CURRENT_VERSION, Context.MODE_PRIVATE)
val themeMode = sharedPreferences.getString("theme_mode", null) ?: ""
val isDarkMode = when (themeMode) {
"\"DARK\"" -> true
"\"LIGHT\"" -> false
Comment on lines +139 to +140
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 SharedPreference에 ThemeMode 저장할 때 큰따옴표도 같이 저장돼??
직렬화할 때 MoshiSerializer#serialize() 타는 거 같은데 moshi가 그렇게 동작하는건가

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 그러게 ThemeMode가 Enum이라 그런가
저장할 때 직렬화를 하는데, getSharedPreferences로 가져와서 그럴까..?
이유는 생각 안해보긴 했어.. ㅋㅋㅋㅋ

else -> isSystemDarkMode(context)
}
Comment on lines +136 to +142
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각보다 앱 내 화면 모드를 가져오는게 어렵지 않았어
만약 그냥 시스템 모드를 가져오는거로 바꾼다면 저 isSystemDarkMode()만 쓰면 되는 상황

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어 isSystemDarkMode 이거 composable 함수인줄 알았는데 아니었구나 ㅋㅋㅋ 굳굳


setBackgroundColor(
if (isDarkMode) Color.rgb(43, 43, 43) else Color.rgb(255, 255, 255),
)
linePaint.apply {
color = if (isDarkMode) Color.rgb(60, 60, 60) else Color.rgb(235, 235, 235)
}
subLinePaint.apply {
color = if (isDarkMode) Color.rgb(60, 60, 60) else Color.rgb(243, 243, 243)
}
hourLabelTextPaint.apply {
color = if (isDarkMode) Color.rgb(119, 119, 119) else Color.rgb(0, 0, 0)
}
dayLabelTextPaint.apply {
color = if (isDarkMode) Color.rgb(119, 119, 119) else Color.rgb(0, 0, 0)
}
Comment on lines +144 to +158
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Color... 좀 마음에 안들게 가져오는데 SNUTTColors꺼를 갖다 쓰는게 안되니
개선한다면 그냥 상수로 들고 있다가 가져오는 정도...가 최선일것 같기도 하고...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단 싸게싸게 ㄱㄱ

}

override fun onDraw(canvas: Canvas) {
Expand Down
Loading