Skip to content

Commit a329315

Browse files
committed
Merge branch 'dev'
2 parents 15ddbe4 + d74ab39 commit a329315

35 files changed

+48656
-38855
lines changed

.github/workflows/android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v5
1111
- name: Set up JDK 21
12-
uses: actions/setup-java@v4
12+
uses: actions/setup-java@v5
1313
with:
1414
java-version: '21'
1515
distribution: 'temurin'

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ android {
1919
applicationId = "org.nsh07.wikireader"
2020
minSdk = 26
2121
targetSdk = 36
22-
versionCode = 49
23-
versionName = "2.5.1"
22+
versionCode = 50
23+
versionName = "2.5.2"
2424

2525
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2626
vectorDrawables {

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
android:label="@string/app_name"
1212
android:supportsRtl="true"
1313
android:theme="@style/Theme.WikiReader.Starting"
14-
android:enableOnBackInvokedCallback="true"
15-
tools:targetApi="35">
14+
android:enableOnBackInvokedCallback="false"
15+
tools:targetApi="36">
1616
<activity
1717
android:name="org.nsh07.wikireader.MainActivity"
1818
android:exported="true"
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,53 @@
11
package org.nsh07.wikireader
22

33
import android.app.Application
4+
import android.content.Context
5+
import android.os.Build.VERSION.SDK_INT
6+
import coil3.ImageLoader
7+
import coil3.SingletonImageLoader
8+
import coil3.gif.AnimatedImageDecoder
9+
import coil3.gif.GifDecoder
10+
import coil3.network.okhttp.OkHttpNetworkFetcherFactory
11+
import coil3.svg.SvgDecoder
12+
import okhttp3.OkHttpClient
413
import org.nsh07.wikireader.data.AppContainer
514
import org.nsh07.wikireader.data.DefaultAppContainer
615

7-
class WikiReaderApplication : Application() {
16+
class WikiReaderApplication : Application(), SingletonImageLoader.Factory {
817
lateinit var container: AppContainer
18+
919
override fun onCreate() {
1020
super.onCreate()
1121
container = DefaultAppContainer(this)
1222
}
23+
24+
override fun newImageLoader(context: Context): ImageLoader {
25+
return ImageLoader.Builder(context)
26+
.components {
27+
add(
28+
OkHttpNetworkFetcherFactory(
29+
OkHttpClient.Builder()
30+
.addNetworkInterceptor { chain ->
31+
chain.proceed(
32+
chain.request()
33+
.newBuilder()
34+
.header(
35+
"User-Agent",
36+
container.userAgentString
37+
)
38+
.build()
39+
)
40+
}
41+
.build()
42+
)
43+
)
44+
add(SvgDecoder.Factory(scaleToDensity = true))
45+
if (SDK_INT >= 28) {
46+
add(AnimatedImageDecoder.Factory())
47+
} else {
48+
add(GifDecoder.Factory())
49+
}
50+
}
51+
.build()
52+
}
1353
}

app/src/main/java/org/nsh07/wikireader/data/AppContainer.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
77
import kotlinx.serialization.json.Json
88
import okhttp3.MediaType.Companion.toMediaType
99
import okhttp3.OkHttpClient
10+
import org.nsh07.wikireader.BuildConfig
1011
import org.nsh07.wikireader.network.HostSelectionInterceptor
1112
import org.nsh07.wikireader.network.WikipediaApiService
1213
import org.nsh07.wikireader.ui.settingsScreen.viewModel.PreferencesState
@@ -20,6 +21,7 @@ interface AppContainer {
2021
val wikipediaRepository: WikipediaRepository
2122
val appPreferencesRepository: AppPreferencesRepository
2223
val appDatabaseRepository: AppDatabaseRepository
24+
val userAgentString: String
2325
}
2426

2527
class DefaultAppContainer(context: Context) : AppContainer {
@@ -30,9 +32,22 @@ class DefaultAppContainer(context: Context) : AppContainer {
3032

3133
override val appStatus = MutableStateFlow(AppStatus.NOT_INITIALIZED)
3234
override val preferencesStateMutableFlow = MutableStateFlow(PreferencesState())
35+
override val userAgentString: String =
36+
"WikiReader/${BuildConfig.VERSION_NAME} (https://github.com/nsh07/wikireader; [email protected]) okhttp/5.1.0 retrofit/3.0.0"
3337

3438
private val okHttpClient by lazy {
3539
OkHttpClient.Builder()
40+
.addNetworkInterceptor { chain ->
41+
chain.proceed(
42+
chain.request()
43+
.newBuilder()
44+
.header(
45+
"User-Agent",
46+
userAgentString
47+
)
48+
.build()
49+
)
50+
}
3651
.addInterceptor(interceptor)
3752
.build()
3853
}

app/src/main/java/org/nsh07/wikireader/parser/wikitextToAnnotatedString.kt

Lines changed: 112 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -716,24 +716,123 @@ fun String.toWikitextAnnotatedString(
716716

717717
currSubstring.startsWith("{{for", true) -> {
718718
val splitList = currSubstring.substringAfter('|').split('|')
719+
.fastFilter { !it.contains('=') }
719720
if (splitList.size > 1) {
720-
append("For ${splitList[0]}, see ")
721-
splitList.subList(1, splitList.size)
722-
.fastForEachIndexed { index: Int, it: String ->
721+
withStyle(SpanStyle(fontStyle = FontStyle.Italic)) {
722+
append("For ${splitList[0]}, see ")
723+
splitList.subList(1, splitList.size)
724+
.fastForEachIndexed { index: Int, it: String ->
725+
append(
726+
"[[${it.substringBefore(MAGIC_SEP)}|${
727+
it.substringAfter(
728+
MAGIC_SEP
729+
)
730+
}]]".twas()
731+
)
732+
733+
if (index == splitList.size - 2 && splitList.size > 2) append(
734+
", and "
735+
)
736+
else if (index < splitList.size - 2) append(", ")
737+
}
738+
append('.')
739+
}
740+
}
741+
}
742+
743+
currSubstring.startsWith("{{about", true) -> {
744+
val splitList = currSubstring.substringAfter('|').split('|')
745+
withStyle(SpanStyle(fontStyle = FontStyle.Italic)) {
746+
when {
747+
currSubstring.matches("\\{\\{[Aa]bout\\|\\|[^|]+\\|[^|]+".toRegex()) -> {
723748
append(
724-
"[[${it.substringBefore(MAGIC_SEP)}|${
725-
it.substringAfter(
726-
MAGIC_SEP
749+
"''For ${splitList[1]}, see [[${
750+
splitList[2].replace(
751+
MAGIC_SEP,
752+
"|"
727753
)
728-
}]]".twas()
754+
}]]''".twas()
755+
)
756+
}
757+
758+
currSubstring.matches("\\{\\{[Aa]bout\\|\\|\\|[^|]+".toRegex()) -> {
759+
append(
760+
"''For other uses, see [[${
761+
splitList.last().replace(MAGIC_SEP, "|")
762+
}]]''".twas()
729763
)
764+
}
730765

731-
if (index == splitList.size - 2 && splitList.size > 2) append(
732-
", and "
766+
currSubstring.matches("\\{\\{[Aa]bout\\|[^|]+\\|\\|[^|]+".toRegex()) -> {
767+
append(
768+
"''This article is about ${splitList[0]}. For other uses, see [[${
769+
splitList[2].replace(
770+
MAGIC_SEP,
771+
"|"
772+
)
773+
}]]''".twas()
733774
)
734-
else if (index < splitList.size - 2) append(", ")
735775
}
736-
append('.')
776+
777+
currSubstring.matches("\\{\\{[Aa]bout\\|[^|]+\\|\\|[^|]+\\|and\\|[^|]+".toRegex()) -> {
778+
append(
779+
"''This article is about ${splitList[0]}. For other uses, see [[${
780+
splitList[2].replace(
781+
MAGIC_SEP,
782+
"|"
783+
)
784+
}]] and [[${
785+
splitList[4].replace(
786+
MAGIC_SEP,
787+
"|"
788+
)
789+
}]].''".twas()
790+
)
791+
}
792+
793+
currSubstring.matches("\\{\\{[Aa]bout\\|[^|]+\\|[^|]+\\|[^|]+".toRegex()) -> {
794+
append(
795+
"''This article is about ${splitList[0]}. For ${splitList[1]}, see [[${
796+
splitList[2].replace(
797+
MAGIC_SEP,
798+
"|"
799+
)
800+
}]].''".twas()
801+
)
802+
}
803+
804+
currSubstring.matches("\\{\\{[Aa]bout\\|[^|]+\\|[^|]+\\|[^|]+\\|and\\|[^|]+".toRegex()) -> {
805+
append(
806+
"''This article is about ${splitList[0]}. For ${splitList[1]}, see [[${
807+
splitList[2].replace(
808+
MAGIC_SEP,
809+
"|"
810+
)
811+
}]] and [[${
812+
splitList[4].replace(
813+
MAGIC_SEP,
814+
"|"
815+
)
816+
}]].''".twas()
817+
)
818+
}
819+
820+
currSubstring.matches("\\{\\{[Aa]bout\\|[^|]+\\|[^|]+\\|[^|]+\\|[^|]+\\|[^|]+".toRegex()) -> {
821+
append(
822+
"''This article is about ${splitList[0]}. For ${splitList[1]}, see [[${
823+
splitList[2].replace(
824+
MAGIC_SEP,
825+
"|"
826+
)
827+
}]]. For ${splitList[3]}, see [[${
828+
splitList[4].replace(
829+
MAGIC_SEP,
830+
"|"
831+
)
832+
}]].''".twas()
833+
)
834+
}
835+
}
737836
}
738837
}
739838

@@ -836,6 +935,7 @@ fun String.toWikitextAnnotatedString(
836935

837936
currSubstring.startsWith("{{further", ignoreCase = true) -> {
838937
val curr = currSubstring.substringAfter('|')
938+
val splitList = curr.split('|').fastFilter { !it.contains('=') }
839939
val topic = curr.substringAfter("topic=", "").substringBefore('|')
840940
withStyle(SpanStyle(fontStyle = FontStyle.Italic)) {
841941
append("Further")
@@ -850,10 +950,7 @@ fun String.toWikitextAnnotatedString(
850950
} else {
851951
append(" reading")
852952
append(
853-
": [[${
854-
curr.substringAfter('|').substringBefore('|')
855-
.substringBefore('#')
856-
}]]\n".twas()
953+
": [[${splitList.getOrNull(0)}]]\n".twas()
857954
)
858955
}
859956
}

app/src/main/java/org/nsh07/wikireader/ui/AppNavigationDrawer.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.nsh07.wikireader.ui
22

33
import androidx.compose.animation.AnimatedVisibility
44
import androidx.compose.animation.Crossfade
5+
import androidx.compose.animation.animateColorAsState
56
import androidx.compose.animation.core.animateDpAsState
67
import androidx.compose.animation.core.animateFloatAsState
78
import androidx.compose.animation.expandHorizontally
@@ -226,10 +227,24 @@ private fun AppNavigationRailContent(
226227
animationSpec = motionScheme.defaultSpatialSpec()
227228
)
228229

230+
val navigationItemSelectedTextColor by animateColorAsState(
231+
if (!expanded) colorScheme.secondary else colorScheme.onSecondaryContainer,
232+
animationSpec = motionScheme.defaultSpatialSpec(),
233+
)
234+
val navigationColors = WideNavigationRailItemDefaults.colors(
235+
unselectedIconColor = colorScheme.onSurfaceVariant,
236+
unselectedTextColor = colorScheme.onSurfaceVariant,
237+
selectedIconColor = colorScheme.onSecondaryContainer,
238+
selectedTextColor = navigationItemSelectedTextColor,
239+
selectedIndicatorColor = colorScheme.secondaryContainer,
240+
)
241+
229242
val sectionColors = WideNavigationRailItemDefaults.colors(
230-
selectedIconColor = colorScheme.onTertiaryContainer,
231-
selectedTextColor = colorScheme.tertiary,
232-
selectedIndicatorColor = colorScheme.tertiaryContainer
243+
unselectedIconColor = colorScheme.onSurfaceVariant,
244+
unselectedTextColor = colorScheme.onSurfaceVariant,
245+
selectedIconColor = colorScheme.onSurface,
246+
selectedTextColor = colorScheme.onSurface,
247+
selectedIndicatorColor = colorScheme.surfaceContainerHighest,
233248
)
234249

235250
Column(
@@ -258,7 +273,8 @@ private fun AppNavigationRailContent(
258273
}
259274
},
260275
label = { Text(stringResource(item.labelId)) },
261-
railExpanded = expanded
276+
railExpanded = expanded,
277+
colors = navigationColors
262278
)
263279
}
264280
if (expanded && backStackEntry?.destination?.hasRoute(HomeScreen::class) == true) {

0 commit comments

Comments
 (0)