-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c79cc16
commit 8321175
Showing
14 changed files
with
389 additions
and
687 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/setting/AbstractSettingState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.setting | ||
|
||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.snapshots.StateFactoryMarker | ||
import indi.dmzz_yyhyy.lightnovelreader.data.userdata.UserData | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
abstract class AbstractSettingState( | ||
private val coroutineScope: CoroutineScope, | ||
) { | ||
|
||
@StateFactoryMarker | ||
protected fun <T> UserData<T>.asState(initial: T): State<T> { | ||
val state = mutableStateOf(getOrDefault(initial)) | ||
coroutineScope.launch(Dispatchers.IO) { | ||
getFlowWithDefault(initial).collect { | ||
state.value = it | ||
} | ||
} | ||
return state | ||
} | ||
|
||
@StateFactoryMarker | ||
protected fun <T> UserData<T>.safeAsState(initial: T): State<T> { | ||
val state = mutableStateOf(initial) | ||
coroutineScope.launch(Dispatchers.IO) { | ||
getFlowWithDefault(initial).collect { | ||
state.value = it | ||
} | ||
} | ||
return state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
268 changes: 90 additions & 178 deletions
268
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/book/content/ContentScreen.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/book/content/SettingState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.ui.book.content | ||
|
||
import androidx.compose.runtime.getValue | ||
import indi.dmzz_yyhyy.lightnovelreader.data.UserDataRepository | ||
import indi.dmzz_yyhyy.lightnovelreader.data.setting.AbstractSettingState | ||
import indi.dmzz_yyhyy.lightnovelreader.data.userdata.UserDataPath | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
class SettingState( | ||
userDataRepository: UserDataRepository, | ||
coroutineScope: CoroutineScope | ||
) : AbstractSettingState(coroutineScope) { | ||
val fontSizeUserData = userDataRepository.floatUserData(UserDataPath.Reader.FontSize.path) | ||
val fontLineHeightUserData = userDataRepository.floatUserData(UserDataPath.Reader.FontLineHeight.path) | ||
val keepScreenOnUserData = userDataRepository.booleanUserData(UserDataPath.Reader.KeepScreenOn.path) | ||
val isUsingFlipPageUserData = userDataRepository.booleanUserData(UserDataPath.Reader.IsUsingFlipPage.path) | ||
val isUsingClickFlipPageUserData = userDataRepository.booleanUserData(UserDataPath.Reader.IsUsingClickFlipPage.path) | ||
val isUsingVolumeKeyFlipUserData = userDataRepository.booleanUserData(UserDataPath.Reader.IsUsingVolumeKeyFlip.path) | ||
val isUsingFlipAnimeUserData = userDataRepository.booleanUserData(UserDataPath.Reader.IsUsingFlipAnime.path) | ||
val fastChapterChangeUserData = userDataRepository.booleanUserData(UserDataPath.Reader.FastChapterChange.path) | ||
val enableBatteryIndicatorUserData = userDataRepository.booleanUserData(UserDataPath.Reader.EnableBatteryIndicator.path) | ||
val enableTimeIndicatorUserData = userDataRepository.booleanUserData(UserDataPath.Reader.EnableTimeIndicator.path) | ||
val enableChapterTitleIndicatorUserData = userDataRepository.booleanUserData( | ||
UserDataPath.Reader.EnableChapterTitleIndicator.path) | ||
val enableReadingChapterProgressIndicatorUserData = userDataRepository.booleanUserData( | ||
UserDataPath.Reader.EnableReadingChapterProgressIndicator.path) | ||
val autoPaddingUserData = userDataRepository.booleanUserData(UserDataPath.Reader.AutoPadding.path) | ||
val topPaddingUserData = userDataRepository.floatUserData(UserDataPath.Reader.TopPadding.path) | ||
val bottomPaddingUserData = userDataRepository.floatUserData(UserDataPath.Reader.BottomPadding.path) | ||
val leftPaddingUserData = userDataRepository.floatUserData(UserDataPath.Reader.LeftPadding.path) | ||
val rightPaddingUserData = userDataRepository.floatUserData(UserDataPath.Reader.RightPadding.path) | ||
|
||
val fontSize by fontSizeUserData.safeAsState(14f) | ||
val fontLineHeight by fontLineHeightUserData.safeAsState(0f) | ||
val keepScreenOn by keepScreenOnUserData.safeAsState(false) | ||
val isUsingFlipPage by isUsingFlipPageUserData.safeAsState(false) | ||
val isUsingClickFlipPage by isUsingClickFlipPageUserData.safeAsState(false) | ||
val isUsingVolumeKeyFlip by isUsingVolumeKeyFlipUserData.safeAsState(false) | ||
val isUsingFlipAnime by isUsingFlipAnimeUserData.safeAsState(true) | ||
val fastChapterChange by fastChapterChangeUserData.safeAsState(false) | ||
val enableBatteryIndicator by enableBatteryIndicatorUserData.safeAsState(true) | ||
val enableTimeIndicator by enableTimeIndicatorUserData.safeAsState(true) | ||
val enableChapterTitleIndicator by enableChapterTitleIndicatorUserData.safeAsState(true) | ||
val enableReadingChapterProgressIndicator by enableReadingChapterProgressIndicatorUserData.safeAsState(true) | ||
val autoPadding by autoPaddingUserData.safeAsState(true) | ||
val topPadding by topPaddingUserData.safeAsState(12f) | ||
val bottomPadding by bottomPaddingUserData.safeAsState(12f) | ||
val leftPadding by leftPaddingUserData.safeAsState(16f) | ||
val rightPadding by rightPaddingUserData.safeAsState(16f) | ||
} |
Oops, something went wrong.