Skip to content

Commit bda26b6

Browse files
committed
新增深色模式独立阅读背景颜色;修复编译时的警告;移除应用语言统计
1 parent a300c13 commit bda26b6

9 files changed

Lines changed: 45 additions & 14 deletions

File tree

api/src/main/kotlin/io/nightfish/lightnovelreader/api/userdata/UserDataPath.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ sealed class UserDataPath(
4343
data object TextDarkColor : UserDataPath("textDarkColor", Reader)
4444
data object FontFamilyUri : UserDataPath("fontFamilyUri", Reader)
4545
data object BackgroundColor : UserDataPath("backgroundColor", Reader)
46+
data object BackgroundDarkColor : UserDataPath("backgroundDarkColor", Reader)
4647
data object BackgroundImageUri : UserDataPath("backgroundImageUri", Reader)
4748
data object BackgroundDarkImageUri : UserDataPath("backgroundDarkImageUri", Reader)
4849
data object BackBlockMode : UserDataPath("backBlockMode", Reader)

app/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android {
2323
minSdk = 24
2424
targetSdk = 36
2525
// 版本号为x.y.z则versionCode为x*1000000+y*10000+z*1000+debug版本号(开发需要时迭代, 三位数)
26-
versionCode = 1_02_00_033
26+
versionCode = 1_02_00_034
2727
versionName = "1.2.0"
2828

2929
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@@ -111,6 +111,10 @@ tasks.withType<KotlinJvmCompile>().configureEach {
111111
}
112112
}
113113

114+
tasks.withType<JavaCompile>().configureEach {
115+
options.compilerArgs.add("-Xlint:-processing")
116+
}
117+
114118
dependencies {
115119
// Desugaring
116120
coreLibraryDesugaring(libs.desugar.jdk.libs)
@@ -153,7 +157,6 @@ dependencies {
153157
implementation(libs.markdown)
154158
// Room
155159
implementation(libs.room.runtime)
156-
annotationProcessor(libs.room.compiler)
157160
ksp(libs.room.compiler)
158161
implementation(libs.room.ktx)
159162
// Splash API

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/book/reader/ReaderScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import androidx.compose.runtime.rememberCoroutineScope
5858
import androidx.compose.runtime.setValue
5959
import androidx.compose.ui.Alignment
6060
import androidx.compose.ui.Modifier
61-
import androidx.compose.ui.graphics.isUnspecified
6261
import androidx.compose.ui.input.nestedscroll.nestedScroll
6362
import androidx.compose.ui.layout.ContentScale
6463
import androidx.compose.ui.platform.LocalContext
@@ -84,6 +83,7 @@ import indi.dmzz_yyhyy.lightnovelreader.ui.components.RollingNumber
8483
import indi.dmzz_yyhyy.lightnovelreader.ui.home.settings.data.MenuOptions
8584
import indi.dmzz_yyhyy.lightnovelreader.utils.LocalClaimSnackbarHost
8685
import indi.dmzz_yyhyy.lightnovelreader.utils.LocalSnackbarHost
86+
import indi.dmzz_yyhyy.lightnovelreader.utils.readerBackgroundColor
8787
import indi.dmzz_yyhyy.lightnovelreader.utils.rememberReaderBackgroundPainter
8888
import indi.dmzz_yyhyy.lightnovelreader.utils.showSnackbar
8989
import io.nightfish.lightnovelreader.api.book.ChapterContent
@@ -196,7 +196,7 @@ fun ReaderScreen(
196196
)
197197
}
198198
},
199-
containerColor = if (settingState.backgroundColor.isUnspecified) colorScheme.background else settingState.backgroundColor,
199+
containerColor = readerBackgroundColor(settingState),
200200
contentWindowInsets = WindowInsets(0, 0, 0, 0)
201201
) { _ ->
202202
if (settingState.enableBackgroundImage) {

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/book/reader/SettingState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class SettingState(
4343
val textDarkColorUserData = userDataRepository.colorUserData(UserDataPath.Reader.TextDarkColor.path)
4444
val fontFamilyUriUserData = userDataRepository.uriUserData(UserDataPath.Reader.FontFamilyUri.path)
4545
val backgroundColorUserData = userDataRepository.colorUserData(UserDataPath.Reader.BackgroundColor.path)
46+
val backgroundDarkColorUserData = userDataRepository.colorUserData(UserDataPath.Reader.BackgroundDarkColor.path)
4647
val backgroundImageUriUserData = userDataRepository.uriUserData(UserDataPath.Reader.BackgroundImageUri.path)
4748
val backgroundDarkImageUriUserData = userDataRepository.uriUserData(UserDataPath.Reader.BackgroundDarkImageUri.path)
4849
val darkModeKeyUserData = userDataRepository.stringUserData(UserDataPath.Settings.Display.DarkMode.path)
@@ -79,6 +80,7 @@ class SettingState(
7980
val textDarkColor by textDarkColorUserData.safeAsState(Color.Unspecified)
8081
val fontFamilyUri by fontFamilyUriUserData.safeAsState(Uri.EMPTY)
8182
val backgroundColor by backgroundColorUserData.safeAsState(Color.Unspecified)
83+
val backgroundDarkColor by backgroundDarkColorUserData.safeAsState(Color.Unspecified)
8284
val backgroundImageUri by backgroundImageUriUserData.safeAsState(Uri.EMPTY)
8385
val backgroundDarkImageUri by backgroundDarkImageUriUserData.safeAsState(Uri.EMPTY)
8486
val darkModeKey by darkModeKeyUserData.safeAsState("FollowSystem")

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/home/settings/theme/ThemeNavigation.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ fun NavGraphBuilder.settingsThemeDestination() {
2929
},
3030
onClickChangeBackgroundColor = {
3131
navController.navigateToColorPickerDialog(
32-
UserDataPath.Reader.BackgroundColor.path,
32+
if (isDark) UserDataPath.Reader.BackgroundDarkColor.path
33+
else UserDataPath.Reader.BackgroundColor.path,
3334
listOf(-1, 0x38E8CCA5, 0x38FF8080, 0x38d3b17d,0x3834C759, 0x3832ADE6, 0x38007AFF, 0x385856D6, 0x38AF52DE)
3435
)
3536
},

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/home/settings/theme/ThemeScreen.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import androidx.compose.ui.Modifier
4949
import androidx.compose.ui.draw.clip
5050
import androidx.compose.ui.geometry.Size
5151
import androidx.compose.ui.graphics.graphicsLayer
52-
import androidx.compose.ui.graphics.isUnspecified
5352
import androidx.compose.ui.layout.ContentScale
5453
import androidx.compose.ui.platform.LocalContext
5554
import androidx.compose.ui.res.painterResource
@@ -83,6 +82,7 @@ import indi.dmzz_yyhyy.lightnovelreader.ui.home.settings.SettingsCategory
8382
import indi.dmzz_yyhyy.lightnovelreader.ui.home.settings.data.MenuOptions
8483
import indi.dmzz_yyhyy.lightnovelreader.utils.LocalSnackbarHost
8584
import indi.dmzz_yyhyy.lightnovelreader.utils.navigationBarSpacer
85+
import indi.dmzz_yyhyy.lightnovelreader.utils.readerBackgroundColor
8686
import indi.dmzz_yyhyy.lightnovelreader.utils.readerTextColor
8787
import indi.dmzz_yyhyy.lightnovelreader.utils.rememberReaderBackgroundPainter
8888
import indi.dmzz_yyhyy.lightnovelreader.utils.rememberReaderFontFamily
@@ -350,6 +350,7 @@ fun ReaderThemeSettingsList(
350350
} else {
351351
val onSecondaryContainer = colorScheme.onSecondaryContainer
352352
val background = colorScheme.background
353+
val currentBgColor = readerBackgroundColor(settingState)
353354
SettingsClickableEntry(
354355
modifier = Modifier.background(colorScheme.surfaceContainer),
355356
painter = painterResource(R.drawable.colorize_24px),
@@ -369,7 +370,7 @@ fun ReaderThemeSettingsList(
369370
radius = 17.5.dp.toPx(),
370371
)
371372
drawCircle(
372-
color = if (settingState.backgroundColor.isUnspecified) background else settingState.backgroundColor,
373+
color = currentBgColor,
373374
radius = 17.5.dp.toPx(),
374375
)
375376
}
@@ -487,7 +488,7 @@ fun ReaderTextSettings(settingState: SettingState, context: Context, onClickChan
487488
contentScale = ContentScale.Crop
488489
)
489490
} else {
490-
Box(modifier = Modifier.fillMaxSize().background(settingState.backgroundColor))
491+
Box(modifier = Modifier.fillMaxSize().background(readerBackgroundColor(settingState)))
491492
}
492493

493494
Text(

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/utils/EncUtils.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,16 @@ fun times(cL: ByteArray): ByteArray {
7676
iP.setInput(cL)
7777
Base64().use { pX ->
7878
val rH = ByteArray(1024)
79-
while (!iP.finished()) {
79+
while (true) {
8080
val tK = iP.inflate(rH)
81-
pX.write(rH, 0, tK)
81+
if (tK > 0) {
82+
pX.write(rH, 0, tK)
83+
continue
84+
}
85+
if (iP.finished()) break
86+
if (iP.needsInput()) break
87+
if (iP.needsDictionary()) break
88+
break
8289
}
8390
iP.end()
8491
return pX.toByteArray()

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/utils/ReaderCustomUtils.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,24 @@ fun rememberReaderBackgroundPainter(
143143
)
144144
}
145145

146+
@Composable
147+
fun readerBackgroundColor(settingState: SettingState): Color {
148+
val localTheme = LocalAppTheme.current
149+
val isDark = localTheme.isDark
150+
val background = localTheme.colorScheme.background
151+
152+
val color = remember(isDark, settingState.backgroundColor, settingState.backgroundDarkColor, background) {
153+
when {
154+
isDark && settingState.backgroundDarkColor.isUnspecified -> background
155+
!isDark && settingState.backgroundColor.isUnspecified -> background
156+
isDark -> settingState.backgroundDarkColor
157+
else -> settingState.backgroundColor
158+
}
159+
}
160+
161+
return color
162+
}
163+
146164
@Composable
147165
fun readerTextColor(settingState: SettingState): Color {
148166
val localTheme = LocalAppTheme.current

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/utils/analytics/MatomoAnalytics.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import org.matomo.sdk.Matomo
2020
import org.matomo.sdk.Tracker
2121
import org.matomo.sdk.TrackerBuilder
2222
import org.matomo.sdk.extra.TrackHelper
23-
import java.util.Locale
2423
import kotlin.time.Duration.Companion.minutes
2524

2625
@Singleton
@@ -34,7 +33,7 @@ class MatomoAnalytics @Inject constructor(
3433
private val coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
3534

3635
companion object {
37-
private const val SERVER = "eNpb85aBtYRBO6OkpKDYSl8_MS8xp7IkM7lYL7m0KDO_tDi1qFgvvyhdPzexJD83X68gowAA2mUS-w"
36+
private const val SERVER = "eNpb85aBtYRBPaOkpKDYSl8_MS8xp7IkM7lYLy-xKDM7Xy-_KF0_N7EkPzdfryCjAACLuxEn"
3837
private const val SITE_ID = 4
3938

4039
private const val DIMENSION_APP_INF = 1
@@ -61,9 +60,8 @@ class MatomoAnalytics @Inject constructor(
6160

6261
private fun buildAppInfo(): String {
6362
val version = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
64-
val locale = Locale.getDefault().toLanguageTag()
6563
val buildType = if (BuildConfig.DEBUG) "debug" else "release"
66-
return "$version, $locale, $buildType"
64+
return "$version, $buildType"
6765
}
6866

6967
private fun buildDeviceInfo(): String {

0 commit comments

Comments
 (0)