Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
383 changes: 229 additions & 154 deletions app/src/main/java/fr/free/nrw/commons/AboutActivity.kt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fr.free.nrw.commons.theme

import androidx.compose.ui.graphics.Color

val PrimaryBlue = Color(0xFF0C609C)
val PrimaryBlueNight = Color(0xFF1E8CAB)
val BackgroundLight = Color(0xFFFAFAFA)
val BackgroundDark = Color(0xFF303030)
val CardBackgroundDark = Color(0xFF1E1E1E)
val CardBackgroundLight = Color(0xFFFFFFFF)
val TextWhite = Color(0xFFFFFFFF)
val TextBlack = Color(0xFF000000)
val Transparent = Color.Transparent
35 changes: 35 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/theme/CommonsTheme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fr.free.nrw.commons.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
fun CommonsTheme(content: @Composable () -> Unit) {
val isDarkTheme = isSystemInDarkTheme()
val colorScheme = if (isDarkTheme) {
darkColorScheme(
primary = PrimaryBlueNight,
background = BackgroundDark,
onBackground = TextWhite,
surfaceVariant = CardBackgroundDark,
onSurface = TextWhite
)
} else {
lightColorScheme(
primary = PrimaryBlue,
background = BackgroundLight,
onBackground = TextBlack,
surfaceVariant = CardBackgroundLight,
onSurface = TextBlack
)
}

MaterialTheme(colorScheme = colorScheme) {
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
content()
}
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/theme/Spacing.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.free.nrw.commons.theme

import androidx.compose.ui.unit.dp

object Spacing {
val none = 0.dp
val extraSmall = 4.dp
val small = 8.dp
val medium = 16.dp
val large = 20.dp
val extraLarge = 24.dp
val huge = 32.dp
val gigantic = 48.dp
}

object Dimensions {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure what's the use of this? I am not sure this is gonna be reused somewhere?

The below makes sense, but having an object for this, I am not sure it's needed. Open for suggestions over here :-)

val cardCorner = 16.dp
val cardElevation = 2.dp

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.android.com/develop/ui/compose/designsystems

The documentation is really good for anyone who wants to dive deeper 🙂

val logoSize = 110.dp
val socialIconBox = 52.dp
val socialIcon = 28.dp
val linkIcon = 20.dp
val cardCorner = 16.dp
val cardElevation = 2.dp
val dividerThickness = 0.5.dp
}
57 changes: 57 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/theme/Type.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package fr.free.nrw.commons.theme

import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.sp

enum class CommonsTextPreset { Headline, Title, Body, Caption }

@Composable
fun CommonsText(
text: String,
preset: CommonsTextPreset,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
textAlign: TextAlign? = null,
maxLines: Int = Int.MAX_VALUE,
overflow: TextOverflow = TextOverflow.Clip,
fontWeight: FontWeight? = null
) {
CommonsText(AnnotatedString(text), preset, modifier, color, textAlign, maxLines, overflow, fontWeight)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a recursion function call. Why can't we pass AnnotatedString as a type parameter so it will support html.

But for now I would recommned let's use the Text directly and have a separate PR that focuses on design tokens and Codex colour, as said by @RitikaPahwa4444, #6791 (comment).

Feel free to have a ToDo that says that once the component is made, it takes it from there something.

}

@Composable
fun CommonsText(
text: AnnotatedString,
preset: CommonsTextPreset,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
textAlign: TextAlign? = null,
maxLines: Int = Int.MAX_VALUE,
overflow: TextOverflow = TextOverflow.Clip,
fontWeight: FontWeight? = null
) {
val style = when (preset) {
CommonsTextPreset.Headline -> TextStyle(fontSize = 24.sp, fontWeight = fontWeight ?: FontWeight.Bold)
CommonsTextPreset.Title -> TextStyle(fontSize = 20.sp, fontWeight = fontWeight ?: FontWeight.Medium)
CommonsTextPreset.Body -> TextStyle(fontSize = 16.sp, fontWeight = fontWeight ?: FontWeight.Normal)
CommonsTextPreset.Caption -> TextStyle(fontSize = 14.sp, fontWeight = fontWeight ?: FontWeight.Normal)
}
Text(
text = text,
modifier = modifier,
style = style,
color = if (color == Color.Unspecified) MaterialTheme.colorScheme.onBackground else color,
textAlign = textAlign,
maxLines = maxLines,
overflow = overflow
)
}
178 changes: 0 additions & 178 deletions app/src/main/res/layout/activity_about.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AboutActivityUnitTests {
@Test
@Throws(Exception::class)
fun testLaunchFacebook() {
activity.launchFacebook(null)
activity.launchFacebook()
val shadowActivity: ShadowActivity = Shadows.shadowOf(activity)
val startedIntent = shadowActivity.nextStartedActivity
Assert.assertEquals(startedIntent.action, "android.intent.action.VIEW")
Expand All @@ -54,43 +54,43 @@ class AboutActivityUnitTests {
@Test
@Throws(Exception::class)
fun testLaunchGithub() {
activity.launchGithub(null)
activity.launchGithub()
}

@Test
@Throws(Exception::class)
fun testLaunchWebsite() {
activity.launchWebsite(null)
activity.launchWebsite()
}

@Test
@Throws(Exception::class)
fun testLaunchRatings() {
activity.launchRatings(null)
activity.launchRatings()
}

@Test
@Throws(Exception::class)
fun testLaunchCredits() {
activity.launchCredits(null)
activity.launchCredits()
}

@Test
@Throws(Exception::class)
fun testLaunchPrivacyPolicy() {
activity.launchPrivacyPolicy(null)
activity.launchPrivacyPolicy()
}

@Test
@Throws(Exception::class)
fun testLaunchUserGuide() {
activity.launchUserGuide(null)
activity.launchUserGuide()
}

@Test
@Throws(Exception::class)
fun testLaunchFrequentlyAskedQuestions() {
activity.launchFrequentlyAskedQuesions(null)
activity.launchFrequentlyAskedQuestions()
}

@Test
Expand Down
Loading