Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose About Activity conversion #5246

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b7f03be
- adds ComposeAboutActivity
Williamrai Jan 21, 2025
7551a9e
- removes XML AboutActivity.kt and its dependencies
Williamrai Jan 22, 2025
f1ca74c
Merge branch 'main' into compose-about-activity
Williamrai Feb 5, 2025
3322431
- adds components for supporting license links in AboutActivity.kt
Williamrai Feb 6, 2025
1a8e91e
- removes deep link from LicenseActivity
Williamrai Feb 7, 2025
7700e06
- code refactor and fixes size issue
Williamrai Feb 7, 2025
000bba6
Merge branch 'main' into compose-about-activity
Williamrai Feb 10, 2025
fc9c93b
Merge branch 'main' into compose-about-activity
Williamrai Feb 11, 2025
dae53c1
Merge branch 'main' into compose-about-activity
cooltey Feb 11, 2025
f9234ed
Merge branch 'main' into compose-about-activity
cooltey Feb 11, 2025
c947643
Merge branch 'main' into compose-about-activity
Williamrai Feb 12, 2025
e1faf46
- design fixes
Williamrai Feb 12, 2025
60bdfa9
Merge branch 'main' into compose-about-activity
Williamrai Feb 12, 2025
6107f86
- design fixes
Williamrai Feb 12, 2025
eb556d3
- design fixes
Williamrai Feb 12, 2025
236177c
Merge branch 'main' into compose-about-activity
cooltey Feb 12, 2025
6cd1799
Merge branch 'main' into compose-about-activity
Williamrai Feb 13, 2025
a2b3741
- code fixes
Williamrai Feb 13, 2025
e6f8bb4
Merge branch 'main' into compose-about-activity
Williamrai Feb 13, 2025
dece384
Merge branch 'main' into compose-about-activity
cooltey Feb 13, 2025
b0f2241
- adds bottom padding to snackbar
Williamrai Feb 14, 2025
a43448f
- removes preview code and license activity xml
Williamrai Feb 14, 2025
5dbfdf6
Merge branch 'main' into compose-about-activity
cooltey Feb 14, 2025
9082311
Merge branch 'main' into compose-about-activity
dbrant Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@
android:name=".settings.NotificationSettingsActivity"
android:label="@string/notification_preferences_title"
android:theme="@style/AppTheme.ActionBar" />
<activity
android:name=".settings.AboutActivity"
android:label="@string/about_activity_title"
android:theme="@style/AppTheme.ActionBar" />
<activity android:name=".settings.languages.WikipediaLanguagesActivity"
android:label="@string/wikipedia_languages_title"/>
<activity
Expand Down Expand Up @@ -190,17 +186,9 @@
android:name=".gallery.GalleryActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.FullScreen" />

<activity
android:name=".settings.LicenseActivity"
android:theme="@style/AppTheme.ActionBar"
tools:ignore="GoogleAppIndexingUrlError"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:pathPrefix="/android_asset/licenses/" android:scheme="content" />
</intent-filter>
</activity>
android:name=".settings.LicenseActivity"/>

<activity
android:name=".feed.news.NewsActivity"
Expand Down Expand Up @@ -372,6 +360,9 @@
<activity
android:name=".donate.GooglePayActivity"/>

<activity
android:name=".settings.AboutActivity"/>

<activity
android:name=".games.onthisday.OnThisDayGameActivity"/>

Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/org/wikipedia/compose/components/HtmlText.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.wikipedia.compose.components

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.fromHtml
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp
import org.wikipedia.compose.theme.WikipediaTheme

@Composable
fun HtmlText(
html: String,
linkStyle: TextLinkStyles = TextLinkStyles(
style = SpanStyle(
color = WikipediaTheme.colors.progressiveColor,
fontSize = 14.sp
)
),
normalStyle: TextStyle = TextStyle(
color = WikipediaTheme.colors.secondaryColor,
fontSize = 14.sp
),
modifier: Modifier = Modifier
) {
Text(
modifier = modifier,
text = AnnotatedString.fromHtml(
htmlString = html,
linkStyles = linkStyle
),
style = normalStyle,
lineHeight = 1.6.em
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.wikipedia.compose.components

import android.content.Intent
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withLink
import androidx.compose.ui.unit.em
import org.wikipedia.compose.theme.WikipediaTheme
import org.wikipedia.settings.LicenseActivity

data class LinkTextData(
val text: String,
val url: String? = null,
val asset: String? = null,
)

@Composable
fun LicenseLinkText(
links: List<LinkTextData>,
textStyle: TextStyle = WikipediaTheme.typography.small,
modifier: Modifier = Modifier
) {
val context = LocalContext.current
val uriHandler = LocalUriHandler.current
val annotatedString = buildAnnotatedString {
links.forEach { linkTextData ->
withLink(
link = LinkAnnotation.Url(
url = linkTextData.url ?: "",
styles = TextLinkStyles(
style = SpanStyle(color = WikipediaTheme.colors.progressiveColor)
),
linkInteractionListener = {
if (linkTextData.asset != null) {
val intent = Intent(context, LicenseActivity::class.java)
intent.putExtra(LicenseActivity.ASSET, linkTextData.asset)
context.startActivity(intent)
} else {
uriHandler.openUri(linkTextData.url ?: "")
}
}
)
) {
append(linkTextData.text)
}
}
}

Text(
text = annotatedString,
modifier = modifier,
style = textStyle,
lineHeight = 1.6.em
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ fun Snackbar(
}
}
},
modifier = modifier.padding(16.dp)
modifier = modifier
.padding(horizontal = 16.dp, vertical = 8.dp),
containerColor = WikipediaTheme.colors.borderColor
) {
Text(
text = message,
style = WikipediaTheme.typography.h3.copy(
color = WikipediaTheme.colors.primaryColor,
letterSpacing = 0.sp
letterSpacing = 0.sp,
),
maxLines = 10,
overflow = TextOverflow.Ellipsis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ fun WikiTopAppBar(
IconButton(onClick = onNavigationClick) {
Icon(
imageVector = navigationIcon,
contentDescription = null
tint = WikipediaTheme.colors.primaryColor,
contentDescription = "Navigate up"
)
}
},
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package org.wikipedia.compose.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider

enum class WikipediaThemeType {
SYSTEM, LIGHT, DARK, BLACK, SEPIA
}
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import org.wikipedia.WikipediaApp
import org.wikipedia.theme.Theme

@Composable
fun BaseTheme(
wikipediaThemeType: WikipediaThemeType = WikipediaThemeType.SYSTEM,
currentTheme: Theme = WikipediaApp.instance.currentTheme,
content: @Composable () -> Unit
) {
val wikipediaColorSystem = when (wikipediaThemeType) {
WikipediaThemeType.LIGHT -> LightColors
WikipediaThemeType.DARK -> DarkColors
WikipediaThemeType.BLACK -> BlackColors
WikipediaThemeType.SEPIA -> SepiaColors
WikipediaThemeType.SYSTEM -> if (isSystemInDarkTheme()) DarkColors else LightColors
val appTheme by remember { mutableStateOf(currentTheme) }

val wikipediaColorSystem = when (appTheme) {
Theme.LIGHT -> LightColors
Theme.DARK -> DarkColors
Theme.BLACK -> BlackColors
Theme.SEPIA -> SepiaColors
}

CompositionLocalProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ val Typography = WikipediaTypography(
),
h3 = TextStyle(
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Bold,
fontWeight = FontWeight.Medium,
fontSize = 16.sp,
lineHeight = 24.sp
),
Expand Down
Loading
Loading