diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt new file mode 100644 index 00000000000..2a56195a198 --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt @@ -0,0 +1,179 @@ +package org.wikipedia.compose.components + +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import org.wikipedia.compose.ComposeColors +import org.wikipedia.compose.theme.BaseTheme +import org.wikipedia.compose.theme.WikipediaTheme + +@Composable +fun AppButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + backgroundColor: Color = WikipediaTheme.colors.progressiveColor, + contentColor: Color = WikipediaTheme.colors.paperColor, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier, + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor, + ), + contentPadding = ButtonDefaults.ContentPadding + ) { + content() + } +} + +@Composable +fun AppTextButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier, + colors = ButtonDefaults.buttonColors( + containerColor = Color.Transparent, + contentColor = contentColor + ), + elevation = ButtonDefaults.elevatedButtonElevation(0.dp) + ) { + content() + } +} + +@Composable +fun OutlineButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + backgroundColor: Color = WikipediaTheme.colors.paperColor, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + borderColor: Color = WikipediaTheme.colors.borderColor, + cornerRadius: Int = 8, + strokeWidth: Int = 1, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier.border( + width = strokeWidth.dp, + color = borderColor, + shape = RoundedCornerShape(cornerRadius.dp) + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ) + ) { + content() + } +} + +@Composable +fun SmallOutlineButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + backgroundColor: Color = WikipediaTheme.colors.paperColor, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + borderColor: Color = WikipediaTheme.colors.borderColor, + cornerRadius: Int = 16, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier.border( + width = 1.dp, + color = borderColor, + shape = RoundedCornerShape(cornerRadius.dp) + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ), + contentPadding = PaddingValues(horizontal = 16.dp) + ) { + content() + } +} + +@Composable +fun ThemeColorCircularButton( + onClick: () -> Unit, + text: String = "Aa", + modifier: Modifier = Modifier, + size: Dp = 40.dp, + defaultBackgroundColor: Color = WikipediaTheme.colors.paperColor, + selectedBackgroundColor: Color = WikipediaTheme.colors.backgroundColor, + borderColor: Color = WikipediaTheme.colors.progressiveColor, + textColor: Color = WikipediaTheme.colors.primaryColor, + rippleColor: Color = Color.Transparent, + isSelected: Boolean = false +) { + Button( + onClick = onClick, + modifier = modifier + .border( + width = 2.dp, + color = if (isSelected) borderColor else Color.Transparent, + shape = CircleShape + ) + .size(size), + colors = ButtonDefaults.buttonColors( + containerColor = if (isSelected) defaultBackgroundColor else selectedBackgroundColor, + contentColor = rippleColor + ), + contentPadding = PaddingValues(0.dp) + ) { + Text( + text = text, + style = WikipediaTheme.typography.h3.copy( + color = textColor, + letterSpacing = 0.sp + ) + ) + } +} + +@Preview(showSystemUi = true) +@Composable +private fun SepiaThemeColorButton() { + BaseTheme { + Column( + modifier = Modifier + .fillMaxSize(), + verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterVertically), + horizontalAlignment = Alignment.CenterHorizontally + ) { + ThemeColorCircularButton( + isSelected = true, + defaultBackgroundColor = ComposeColors.Beige300, + selectedBackgroundColor = ComposeColors.Beige300, + rippleColor = ComposeColors.Beige300, + textColor = ComposeColors.Gray700, + onClick = {} + ) + } + } +} diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt b/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt new file mode 100644 index 00000000000..a59f9ac613a --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt @@ -0,0 +1,51 @@ +package org.wikipedia.compose.components + +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Snackbar +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import org.wikipedia.compose.theme.WikipediaTheme + +@Composable +fun Snackbar( + message: String, + modifier: Modifier = Modifier, + actionLabel: String? = null, + onActionClick: (() -> Unit)? = null, +) { + Snackbar( + action = { + if (actionLabel != null && onActionClick != null) { + TextButton( + onClick = onActionClick, + modifier = Modifier.padding(end = 8.dp) + ) { + Text( + text = actionLabel, + style = WikipediaTheme.typography.h3.copy( + color = WikipediaTheme.colors.progressiveColor + ) + ) + } + } + }, + modifier = modifier.padding(16.dp) + ) { + Text( + text = message, + style = WikipediaTheme.typography.h3.copy( + color = WikipediaTheme.colors.primaryColor, + letterSpacing = 0.sp + ), + maxLines = 10, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .padding(top = 0.dp, bottom = 0.dp, start = 0.dp, end = 8.dp) + ) + } +} diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiTopAppBar.kt b/app/src/main/java/org/wikipedia/compose/components/WikiTopAppBar.kt new file mode 100644 index 00000000000..4e47d3f8942 --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/components/WikiTopAppBar.kt @@ -0,0 +1,54 @@ +package org.wikipedia.compose.components + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import org.wikipedia.compose.theme.WikipediaTheme + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun WikiTopAppBar( + title: String, + onNavigationClick: (() -> Unit), + titleStyle: TextStyle = WikipediaTheme.typography.h1.copy(lineHeight = 24.sp), + elevation: Dp = 0.dp, + modifier: Modifier = Modifier +) { + val navigationIcon = Icons.AutoMirrored.Filled.ArrowBack + val backgroundColor = WikipediaTheme.colors.paperColor + + TopAppBar( + title = { + Text( + text = title, + style = titleStyle, + color = WikipediaTheme.colors.primaryColor + ) + }, + navigationIcon = { + IconButton(onClick = onNavigationClick) { + Icon( + imageVector = navigationIcon, + contentDescription = null + ) + } + }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = backgroundColor, + titleContentColor = WikipediaTheme.colors.primaryColor + ), + modifier = modifier.shadow(elevation = elevation) + ) +} diff --git a/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt index d1aa7fb0078..5f700e87bd2 100644 --- a/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt +++ b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt @@ -22,7 +22,8 @@ fun BaseTheme( } CompositionLocalProvider( - LocalWikipediaColor provides wikipediaColorSystem + LocalWikipediaColor provides wikipediaColorSystem, + LocalWikipediaTypography provides Typography ) { content() } @@ -32,4 +33,8 @@ object WikipediaTheme { val colors: WikipediaColor @Composable get() = LocalWikipediaColor.current + + val typography: WikipediaTypography + @Composable + get() = LocalWikipediaTypography.current } diff --git a/app/src/main/java/org/wikipedia/compose/theme/WikipediaTypography.kt b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTypography.kt new file mode 100644 index 00000000000..9eb32d4a6a5 --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTypography.kt @@ -0,0 +1,90 @@ +package org.wikipedia.compose.theme + +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +@Immutable +data class WikipediaTypography( + val h1: TextStyle = TextStyle(), + val h2: TextStyle = TextStyle(), + val h3: TextStyle = TextStyle(), + val h4: TextStyle = TextStyle(), + val h5: TextStyle = TextStyle(), + val p: TextStyle = TextStyle(), + val button: TextStyle = TextStyle(), + val article: TextStyle = TextStyle(), + val list: TextStyle = TextStyle(), + val chip: TextStyle = TextStyle(), + val small: TextStyle = TextStyle() +) + +val LocalWikipediaTypography = staticCompositionLocalOf { + WikipediaTypography() +} + +val Typography = WikipediaTypography( + h1 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 24.sp, + lineHeight = 32.sp + ), + h2 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 20.sp, + lineHeight = 28.sp + ), + h3 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 16.sp, + lineHeight = 24.sp + ), + h4 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 14.sp, + lineHeight = 24.sp + ), + h5 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 12.sp, + lineHeight = 18.sp + ), + button = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Medium, + fontSize = 16.sp, + lineHeight = 24.sp + ), + article = TextStyle( + fontFamily = FontFamily.Serif, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp + ), + list = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Normal, + fontSize = 14.sp, + lineHeight = 24.sp + ), + chip = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + lineHeight = 24.sp + ), + small = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Medium, + fontSize = 12.sp, + lineHeight = 18.sp + ) +) diff --git a/app/src/main/java/org/wikipedia/dataclient/Service.kt b/app/src/main/java/org/wikipedia/dataclient/Service.kt index 80c8ba4a148..4a85b81535a 100644 --- a/app/src/main/java/org/wikipedia/dataclient/Service.kt +++ b/app/src/main/java/org/wikipedia/dataclient/Service.kt @@ -92,7 +92,7 @@ interface Service { @GET( MW_API_PREFIX + "action=query&generator=search&gsrnamespace=0&gsrqiprofile=classic_noboostlinks" + - "&origin=*&piprop=thumbnail&prop=pageimages|description|info|pageprops" + + "&origin=*&piprop=thumbnail&pilicense=any&prop=pageimages|description|info|pageprops" + "&inprop=varianttitles&smaxage=86400&maxage=86400&pithumbsize=" + PREFERRED_THUMB_SIZE ) suspend fun searchMoreLike( @@ -112,7 +112,7 @@ interface Service { @GET(MW_API_PREFIX + "action=query&prop=description&redirects=1") suspend fun getDescription(@Query("titles") titles: String): MwQueryResponse - @GET(MW_API_PREFIX + "action=query&prop=info|description|pageimages&inprop=varianttitles|displaytitle&redirects=1&pithumbsize=" + PREFERRED_THUMB_SIZE) + @GET(MW_API_PREFIX + "action=query&prop=info|description|pageimages&pilicense=any&inprop=varianttitles|displaytitle&redirects=1&pithumbsize=" + PREFERRED_THUMB_SIZE) suspend fun getInfoByPageIdsOrTitles(@Query("pageids") pageIds: String? = null, @Query("titles") titles: String? = null): MwQueryResponse @GET(MW_API_PREFIX + "action=query&meta=siteinfo&siprop=general|autocreatetempuser") @@ -172,7 +172,7 @@ interface Service { @GET(MW_API_PREFIX + "action=query&prop=info&generator=categories&inprop=varianttitles|displaytitle&gclshow=!hidden&gcllimit=500") suspend fun getCategories(@Query("titles") titles: String): MwQueryResponse - @GET(MW_API_PREFIX + "action=query&prop=description|pageimages|info&generator=categorymembers&inprop=varianttitles|displaytitle&gcmprop=ids|title") + @GET(MW_API_PREFIX + "action=query&prop=description|pageimages|info&pilicense=any&generator=categorymembers&inprop=varianttitles|displaytitle&gcmprop=ids|title") suspend fun getCategoryMembers( @Query("gcmtitle") title: String, @Query("gcmtype") type: String, diff --git a/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt b/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt index 0b0777febbd..1612852749e 100644 --- a/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt +++ b/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt @@ -324,7 +324,14 @@ object EditingSuggestionsProvider { // TODO: make use of continuation parameter? response.query?.pages?.forEach { page -> if (page.thumbUrl().isNullOrEmpty() && page.growthimagesuggestiondata?.get(0)?.images?.get(0) != null) { - articlesWithImageRecommendationsCache.addFirst(page) + if (articlesWithImageRecommendationsCacheLang == "de") { + // In the case of dewiki, make sure the image is CC-licensed: + if (page.growthimagesuggestiondata[0].images[0].metadata?.license.orEmpty().lowercase().contains("cc")) { + articlesWithImageRecommendationsCache.addFirst(page) + } + } else { + articlesWithImageRecommendationsCache.addFirst(page) + } } } } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 2010a4f6e9d..d5664969a49 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -551,19 +551,6 @@ @style/TextInputLayoutErrorTextAppearance - -