Skip to content

Commit 120f13a

Browse files
authored
Merge pull request #346 from dmzz-yyhyy/bugfix
错误修复
2 parents aa0c3c0 + bda26b6 commit 120f13a

62 files changed

Lines changed: 1443 additions & 533 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ afterEvaluate {
6565
repositories {
6666
maven {
6767
name = "reposilite"
68-
url = URI("https://maven.curiousers.org/release")
68+
url = URI("https://maven.nariko.org/release")
6969
credentials {
7070
username = System.getenv("REPO_USER")
7171
password = System.getenv("REPO_PASS")

api/src/main/kotlin/io/nightfish/lightnovelreader/api/ui/Local.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package io.nightfish.lightnovelreader.api.ui
22

33
import androidx.compose.runtime.compositionLocalOf
44
import androidx.compose.ui.graphics.Color
5+
import androidx.compose.ui.text.intl.Locale
6+
import androidx.compose.ui.text.intl.LocaleList
57
import androidx.navigation.NavController
68

79
val LocalNavController = compositionLocalOf<NavController> {
@@ -16,4 +18,24 @@ val LocalReaderStyle = compositionLocalOf {
1618
textColor = Color.Unspecified,
1719
textDarkColor = Color.Unspecified,
1820
)
21+
}
22+
23+
val LocalTextLocaleList = compositionLocalOf {
24+
LocaleList(Locale.current)
25+
}
26+
27+
fun appLocaleToTextLocaleList(appLocale: String): LocaleList {
28+
val parts = appLocale.split("-")
29+
val language = parts.getOrNull(0).orEmpty()
30+
val region = parts.getOrNull(1).orEmpty()
31+
32+
val tag = buildString {
33+
append(language.ifBlank { "en" })
34+
if (region.isNotBlank()) {
35+
append("-")
36+
append(region)
37+
}
38+
}
39+
40+
return LocaleList(Locale(tag))
1941
}

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

Lines changed: 5 additions & 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)
@@ -67,6 +68,10 @@ sealed class UserDataPath(
6768
data object AppLocale : UserDataPath("app_locale", Display)
6869
data object LightThemeName : UserDataPath("light_theme_name", Display)
6970
data object DarkThemeName : UserDataPath("dark_theme_name", Display)
71+
data object DateStyle : UserDataPath("date_style", Display)
72+
data object DateShowYear : UserDataPath("date_show_year", Display)
73+
data object DateOrder : UserDataPath("date_order", Display)
74+
data object RelativeTimeStyle : UserDataPath("relative_time_style", Display)
7075
}
7176
data object Data: UserDataPath("data", Settings) {
7277
data object WebDataSourceId : UserDataPath("web_data_source_id", Data)

app/build.gradle.kts

Lines changed: 9 additions & 6 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_030
26+
versionCode = 1_02_00_034
2727
versionName = "1.2.0"
2828

2929
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@@ -63,8 +63,8 @@ android {
6363
getDefaultProguardFile("proguard-android-optimize.txt"),
6464
"proguard-rules.pro"
6565
)
66-
val dateFormat = SimpleDateFormat("MMM-dd-HH-mm-ss", Locale.US)
67-
versionNameSuffix = "-${dateFormat.format(Date())}"
66+
val dateFormat = SimpleDateFormat("yyyy/MM/dd", Locale.US)
67+
versionNameSuffix = "_SN (${dateFormat.format(Date())})"
6868
}
6969

7070
base {
@@ -93,8 +93,8 @@ androidComponents {
9393
variant.outputs.forEach { output ->
9494
val outputImpl = output as com.android.build.api.variant.impl.VariantOutputImpl
9595
val originalFileName = outputImpl.outputFileName.get()
96-
val dateFormat = SimpleDateFormat("MMM-dd-HH-mm-ss", Locale.US)
97-
val newFileName = originalFileName.replace(".apk", "-${dateFormat.format(Date())}.apk")
96+
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US)
97+
val newFileName = originalFileName.replace(".apk", " (${dateFormat.format(Date())}).apk")
9898
outputImpl.outputFileName = newFileName
9999
}
100100
}
@@ -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/MainActivity.kt

Lines changed: 94 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package indi.dmzz_yyhyy.lightnovelreader
22

33
import android.Manifest.permission.POST_NOTIFICATIONS
44
import android.content.pm.PackageManager
5+
import android.content.res.Configuration
56
import android.content.res.Resources
67
import android.os.Build
78
import android.os.Bundle
@@ -14,7 +15,6 @@ import androidx.compose.runtime.mutableStateOf
1415
import androidx.compose.runtime.remember
1516
import androidx.compose.runtime.setValue
1617
import androidx.compose.ui.graphics.Color
17-
import androidx.compose.ui.text.intl.Locale
1818
import androidx.core.app.ActivityCompat
1919
import androidx.core.content.ContextCompat
2020
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
@@ -31,6 +31,7 @@ import indi.dmzz_yyhyy.lightnovelreader.data.web.WebBookDataSourceProvider
3131
import indi.dmzz_yyhyy.lightnovelreader.data.work.CheckUpdateWork
3232
import indi.dmzz_yyhyy.lightnovelreader.theme.LightNovelReaderTheme
3333
import indi.dmzz_yyhyy.lightnovelreader.ui.LightNovelReaderApp
34+
import indi.dmzz_yyhyy.lightnovelreader.utils.FormattingSettings
3435
import indi.dmzz_yyhyy.lightnovelreader.utils.LogUtils
3536
import io.nightfish.lightnovelreader.api.bookshelf.BookshelfSortType
3637
import io.nightfish.lightnovelreader.api.ui.ReaderStyle
@@ -54,65 +55,31 @@ class MainActivity : ComponentActivity() {
5455
@Inject lateinit var webBookDataSourceProvider: WebBookDataSourceProvider
5556
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
5657

58+
private var appLocale by mutableStateOf(
59+
Resources.getSystem().configuration.locales[0].let { "${it.language}-${it.country}" }
60+
)
61+
private var darkMode by mutableStateOf("FollowSystem")
62+
private var dynamicColor by mutableStateOf(false)
63+
private var enableM3E by mutableStateOf(false)
64+
private var lightThemeName by mutableStateOf("light_default")
65+
private var darkThemeName by mutableStateOf("dark_default")
66+
5767
override fun onCreate(savedInstanceState: Bundle?) {
5868
installSplashScreen()
5969
enableEdgeToEdge()
6070
super.onCreate(savedInstanceState)
6171
Thread.setDefaultUncaughtExceptionHandler(LogUtils(applicationContext, loggerRepository))
62-
var appLocale by mutableStateOf("${Locale.current.platformLocale.language}-${Locale.current.platformLocale.variant}")
63-
var darkMode by mutableStateOf("FollowSystem")
64-
var dynamicColor by mutableStateOf(false)
65-
var enableM3E by mutableStateOf(false)
66-
var lightThemeName by mutableStateOf("light_default")
67-
var darkThemeName by mutableStateOf("dark_default")
6872

6973
workManager.enqueueUniquePeriodicWork(
7074
"checkUpdate",
7175
ExistingPeriodicWorkPolicy.KEEP,
7276
PeriodicWorkRequestBuilder<CheckUpdateWork>(12, TimeUnit.HOURS)
7377
.build()
7478
)
75-
coroutineScope.launch(Dispatchers.IO) {
76-
if (bookshelfRepository.getAllBookshelfIds().isEmpty())
77-
bookshelfRepository.createBookShelf(
78-
id = 1145140721,
79-
name = "已收藏",
80-
sortType = BookshelfSortType.Default,
81-
autoCache = false,
82-
systemUpdateReminder = false
83-
)
84-
}
85-
coroutineScope.launch(Dispatchers.IO) {
86-
userDataRepository.stringUserData(UserDataPath.Settings.Display.AppLocale.path)
87-
.getFlow()
88-
.collect { value ->
89-
val locale = Resources.getSystem().configuration.locales[0]
90-
val systemLocale = "${locale.language}-${locale.country}"
91-
appLocale = if (value.isNullOrBlank() || value == "none") systemLocale
92-
else value
93-
}
94-
}
79+
initDefaultBookshelf()
80+
observeDisplaySettings()
81+
observeFormattingSettings()
9582

96-
coroutineScope.launch(Dispatchers.IO) {
97-
userDataRepository.stringUserData(UserDataPath.Settings.Display.DarkMode.path).getFlow().collect {
98-
darkMode = it ?: "FollowSystem"
99-
}
100-
}
101-
coroutineScope.launch(Dispatchers.IO) {
102-
userDataRepository.stringUserData(UserDataPath.Settings.Display.LightThemeName.path).getFlow().collect {
103-
it?.let { lightThemeName = it }
104-
}
105-
}
106-
coroutineScope.launch(Dispatchers.IO) {
107-
userDataRepository.stringUserData(UserDataPath.Settings.Display.DarkThemeName.path).getFlow().collect {
108-
it?.let { darkThemeName = it }
109-
}
110-
}
111-
coroutineScope.launch(Dispatchers.IO) {
112-
userDataRepository.booleanUserData(UserDataPath.Settings.Display.EnableM3E.path).getFlow().collect {
113-
it?.let { enableM3E = it }
114-
}
115-
}
11683
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { /* Android 13 + */
11784
if (ContextCompat.checkSelfPermission(this, POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
11885
ActivityCompat.requestPermissions(
@@ -121,14 +88,6 @@ class MainActivity : ComponentActivity() {
12188
}
12289
}
12390

124-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
125-
coroutineScope.launch(Dispatchers.IO) {
126-
userDataRepository.booleanUserData(UserDataPath.Settings.Display.DynamicColors.path).getFlow().collect {
127-
dynamicColor = it == true
128-
}
129-
}
130-
}
131-
13291
val fontSizeUserData = userDataRepository.floatUserData(UserDataPath.Reader.FontSize.path)
13392
val fontLineHeightUserData = userDataRepository.floatUserData(UserDataPath.Reader.FontLineHeight.path)
13493
val fontWeightUserData = userDataRepository.floatUserData(UserDataPath.Reader.FontWeigh.path)
@@ -179,8 +138,88 @@ class MainActivity : ComponentActivity() {
179138
}
180139
}
181140

141+
private fun initDefaultBookshelf() {
142+
coroutineScope.launch(Dispatchers.IO) {
143+
if (bookshelfRepository.getAllBookshelfIds().isEmpty())
144+
bookshelfRepository.createBookShelf(
145+
id = 1145140721,
146+
name = "已收藏",
147+
sortType = BookshelfSortType.Default,
148+
autoCache = false,
149+
systemUpdateReminder = false
150+
)
151+
}
152+
}
153+
154+
private fun observeDisplaySettings() {
155+
coroutineScope.launch(Dispatchers.IO) {
156+
userDataRepository.stringUserData(UserDataPath.Settings.Display.AppLocale.path)
157+
.getFlow()
158+
.collect { value ->
159+
val locale = Resources.getSystem().configuration.locales[0]
160+
val systemLocale = "${locale.language}-${locale.country}"
161+
appLocale = if (value.isNullOrBlank() || value == "none") systemLocale
162+
else value
163+
}
164+
}
165+
coroutineScope.launch(Dispatchers.IO) {
166+
userDataRepository.stringUserData(UserDataPath.Settings.Display.DarkMode.path).getFlow().collect {
167+
it?.let { darkMode = it }
168+
}
169+
}
170+
coroutineScope.launch(Dispatchers.IO) {
171+
userDataRepository.stringUserData(UserDataPath.Settings.Display.LightThemeName.path).getFlow().collect {
172+
it?.let { lightThemeName = it }
173+
}
174+
}
175+
coroutineScope.launch(Dispatchers.IO) {
176+
userDataRepository.stringUserData(UserDataPath.Settings.Display.DarkThemeName.path).getFlow().collect {
177+
it?.let { darkThemeName = it }
178+
}
179+
}
180+
coroutineScope.launch(Dispatchers.IO) {
181+
userDataRepository.booleanUserData(UserDataPath.Settings.Display.EnableM3E.path).getFlow().collect {
182+
it?.let { enableM3E = it }
183+
}
184+
}
185+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
186+
coroutineScope.launch(Dispatchers.IO) {
187+
userDataRepository.booleanUserData(UserDataPath.Settings.Display.DynamicColors.path).getFlow().collect {
188+
dynamicColor = it == true
189+
}
190+
}
191+
}
192+
}
193+
194+
private fun observeFormattingSettings() {
195+
coroutineScope.launch(Dispatchers.IO) {
196+
userDataRepository.stringUserData(UserDataPath.Settings.Display.DateStyle.path).getFlow().collect {
197+
it?.let { FormattingSettings.dateFormat = it }
198+
}
199+
}
200+
coroutineScope.launch(Dispatchers.IO) {
201+
userDataRepository.booleanUserData(UserDataPath.Settings.Display.DateShowYear.path).getFlow().collect {
202+
it?.let { FormattingSettings.dateShowYear = it }
203+
}
204+
}
205+
coroutineScope.launch(Dispatchers.IO) {
206+
userDataRepository.stringUserData(UserDataPath.Settings.Display.DateOrder.path).getFlow().collect {
207+
it?.let { FormattingSettings.dateOrder = it }
208+
}
209+
}
210+
coroutineScope.launch(Dispatchers.IO) {
211+
userDataRepository.booleanUserData(UserDataPath.Settings.Display.RelativeTimeStyle.path).getFlow().collect {
212+
it?.let { FormattingSettings.useRelativeTime = it }
213+
}
214+
}
215+
}
216+
182217
override fun onDestroy() {
183218
super.onDestroy()
184219
coroutineScope.cancel()
185220
}
221+
222+
override fun onConfigurationChanged(newConfig: Configuration) {
223+
super.onConfigurationChanged(newConfig)
224+
}
186225
}

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/local/room/entity/UserDataEntity.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,15 @@ data class UserDataEntity(
1313
val type: String,
1414
val value: String
1515
): Mergeable<UserDataEntity> {
16-
override fun merge(new: UserDataEntity): UserDataEntity = new
16+
override fun merge(new: UserDataEntity): UserDataEntity {
17+
return when (type) {
18+
"StringList" -> copy(
19+
value = (value.split(",") + new.value.split(","))
20+
.filter { it.isNotBlank() }
21+
.distinct()
22+
.joinToString(",")
23+
)
24+
else -> new
25+
}
26+
}
1727
}

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/update/APIParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java.util.zip.ZipFile
1515
*/
1616
object APIParser {
1717
private const val TAG = "APIParser"
18-
private const val BASE_URL = "https://lnr.curiousers.org"
18+
private const val BASE_URL = "https://lnr.nariko.org"
1919
private const val API_PATH = "/api/update"
2020

2121
class APIRelease(

0 commit comments

Comments
 (0)