Skip to content

Commit 310d5c8

Browse files
committed
Add support for Italian and French citations
Full text is not displayed however, only the source is displayed. #195
1 parent 336ca46 commit 310d5c8

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import org.nsh07.wikireader.parser.ReferenceData.refCount
3030
import org.nsh07.wikireader.parser.ReferenceData.refList
3131
import org.nsh07.wikireader.parser.ReferenceData.refListCount
3232
import org.nsh07.wikireader.parser.ReferenceData.refListIndex
33+
import org.nsh07.wikireader.parser.ReferenceData.refTemplate
34+
import org.nsh07.wikireader.parser.ReferenceData.refTemplates
3335
import kotlin.math.min
3436
import kotlin.text.Typography.bullet
3537
import kotlin.text.Typography.nbsp
@@ -334,8 +336,13 @@ fun String.toWikitextAnnotatedString(
334336
val currSubstring =
335337
substringMatchingParen('{', '}', i).substringBeforeLast("}}")
336338
when {
337-
currSubstring.startsWith("{{cite", ignoreCase = true) -> {
338-
val text = if (currSubstring.startsWith("{{cite book", true)) {
339+
refTemplates.fastAny { item ->
340+
currSubstring
341+
.startsWith(item, ignoreCase = true)
342+
.also { if (it) refTemplate = item }
343+
} -> {
344+
val text =
345+
if (currSubstring.startsWith("$refTemplate book", true)) {
339346
val params = mutableMapOf<String, String>()
340347

341348
// Extract inside of {{Cite book ...}}
@@ -382,10 +389,10 @@ fun String.toWikitextAnnotatedString(
382389
.trim()
383390
.twas()
384391
} else if (
385-
currSubstring.startsWith("{{cite web", true) ||
386-
currSubstring.startsWith("{{cite news", true) ||
387-
currSubstring.startsWith("{{cite AV media", true) ||
388-
currSubstring.startsWith("{{cite press release", true)
392+
currSubstring.startsWith("$refTemplate web", true) ||
393+
currSubstring.startsWith("$refTemplate news", true) ||
394+
currSubstring.startsWith("$refTemplate AV media", true) ||
395+
currSubstring.startsWith("$refTemplate press release", true)
389396
) {
390397
val params = mutableMapOf<String, String>()
391398

@@ -443,7 +450,11 @@ fun String.toWikitextAnnotatedString(
443450
.plus(".")
444451
.trim()
445452
.twas()
446-
} else if (currSubstring.startsWith("{{cite journal", true)) {
453+
} else if (currSubstring.startsWith(
454+
"$refTemplate journal",
455+
true
456+
)
457+
) {
447458
val params = mutableMapOf<String, String>()
448459

449460
// Extract inside of {{Cite journal ...}}
@@ -1147,7 +1158,7 @@ fun String.buildRefList() {
11471158

11481159
fun String.splitNotInBraces(delimiter: Char, open: Char = '[', close: Char = ']'): List<String> {
11491160
var stack = 0
1150-
var out = mutableListOf<String>()
1161+
val out = mutableListOf<String>()
11511162
var curr = ""
11521163

11531164
for (c in this) {
@@ -1174,4 +1185,6 @@ object ReferenceData {
11741185
val refList = mutableMapOf<String, String>()
11751186
val refListIndex = mutableMapOf<Int, String>()
11761187
val refListCount = mutableMapOf<String, Int>()
1188+
var refTemplate = "{{cite"
1189+
val refTemplates = listOf("{{cite", "{{lien", "{{cita")
11771190
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ private fun StatusBarProtection(
716716
val gradient = Brush.verticalGradient(
717717
colors = listOf(
718718
color.copy(alpha = 1f),
719-
color.copy(alpha = 0.8f),
719+
color.copy(alpha = 0.7f),
720720
Color.Transparent
721721
),
722722
startY = 0f,

app/src/main/java/org/nsh07/wikireader/ui/homeScreen/AsyncInfobox.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import androidx.compose.ui.platform.LocalContext
4343
import androidx.compose.ui.res.stringResource
4444
import androidx.compose.ui.text.AnnotatedString
4545
import androidx.compose.ui.text.font.FontWeight
46+
import androidx.compose.ui.text.style.TextAlign
4647
import androidx.compose.ui.unit.dp
4748
import androidx.compose.ui.unit.sp
4849
import androidx.compose.ui.util.fastAny
@@ -110,13 +111,14 @@ fun AsyncInfobox(
110111
}
111112
},
112113
headlineContent = {
113-
Row {
114+
Row(verticalAlignment = Alignment.CenterVertically) {
114115
Text(stringResource(R.string.infobox), fontWeight = FontWeight.Medium)
115116
Spacer(Modifier.width(8.dp))
116117
AnimatedVisibility(!expanded) {
117118
Text(
118119
title ?: AnnotatedString(""),
119120
color = colorScheme.outline,
121+
textAlign = TextAlign.Center,
120122
modifier = Modifier
121123
.sharedBounds(
122124
sharedContentState = rememberSharedContentState(
@@ -144,6 +146,7 @@ fun AsyncInfobox(
144146
Text(
145147
title ?: AnnotatedString(""),
146148
style = typography.headlineSmall,
149+
textAlign = TextAlign.Center,
147150
modifier = Modifier
148151
.sharedBounds(
149152
sharedContentState = rememberSharedContentState(

0 commit comments

Comments
 (0)